不会为 ttk Treeview 小部件激活水平滚动 [英] Horizontal scrolling won't activate for ttk Treeview widget

查看:31
本文介绍了不会为 ttk Treeview 小部件激活水平滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ttk Treeview 小部件来实现文件夹/路径选择对话框.除了我的水平滚动条不会激活之外,一切都按预期工作.无论文件夹路径的水平方向有多宽,也无论窗口有多窄,水平滑块都不会出现.不过垂直滚动效果很好.

I'm using the ttk Treeview widget to implement a folder/path selection dialog. It's all working as expected except that my horizontal scrollbar won't activate. No matter how wide the folder path goes horizontally, and no matter how narrow the window, the horizontal slider never appears. Vertical scrolling is working perfectly though.

我认为这要么是在树视图中仅使用一列时的某种限制,要么只是配置和连接小部件的新手错误.我打赌后者.

I'm figuring it's either some kind of limitation when you only use one column in the treeview, or just a newbie mistake with configuring and connecting the widgets. I'd bet on the latter.

对话框加宽以显示完整文件夹深度的示例:

Example with dialog widened to show full folder depth:

对话框缩小到水平滚动应该激活(但没有)的点:

Dialog narrowed to the point where horizontal scrolling should activate (but doesn't):

这是我的 GUI 布局代码:

Here's my GUI layout code:

winDirSel = tk.Toplevel()
winDirSel.title('Select Test Directory...')
tvwDirSel = ttk.Treeview(winDirSel,
                         height=10,padding=3,
                         show='tree')
lblTestDir = tk.Label(winDirSel, relief=tk.SUNKEN,
                      justify=tk.LEFT, anchor=tk.W,
                      textvariable=ctrlTestDir,width=80)
scbHDirSel = ttk.Scrollbar(winDirSel,
                           orient=tk.HORIZONTAL,
                           command=tvwDirSel.xview)
scbVDirSel = ttk.Scrollbar(winDirSel,
                           orient=tk.VERTICAL,
                           command=tvwDirSel.yview)
tvwDirSel.configure(xscrollcommand=scbHDirSel.set,
                    yscrollcommand=scbVDirSel.set)
lblTestDir.grid(row=0,column=0,sticky=tk.EW)
tvwDirSel.grid(row=1,column=0,sticky=tk.NSEW)
scbVDirSel.grid(row=1,column=1,sticky=tk.NS)
scbHDirSel.grid(row=2,column=0,sticky=tk.EW)
winDirSel.rowconfigure(1,weight=1)
winDirSel.columnconfigure(0,weight=1)

推荐答案

OK,在玩了一些 minwidthstretch 之后,我觉得我对它有更好的把握.水平滚动由超出窗口边界的 column-edge 触发,而不是由列的内容触发.所以你可以使用这些参数来强制列更宽,从而强制滚动.

OK, after some playing with minwidth and stretch, I think I have a better handle on it. The horizontal scrolling is triggered by the column-edge going out of the window's bounds, not the content of the column. So you can use these parameters to force the column to be wider and thus force the scrolling.

但问题是,您会失去自动调整列宽以适应树本身的宽度的功能.您要么必须将其设置得非常宽以适应任何(假设的)可能的文件夹深度,要么您不得不忍受文件夹名称在列的右边界处被截断的情况.

The problem though is that you then lose the automatic adjustment of the column width to suit the width of the tree itself. You either have to force it very wide to accommodate any (assumed) likely folder depth, or you live with folder names getting truncated at the right boundary of the column.

所以最重要的是:这只是小部件本身的限制.(至少关于它在我的平台 MS Windows 上的行为.)

So bottom line: it's just a limitation of the widget itself. (At least with respect to its behavior on my platform, MS Windows.)

这篇关于不会为 ttk Treeview 小部件激活水平滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆