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

查看:190
本文介绍了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)

推荐答案

好的,在玩过minwidthstretch之后,我认为我对它有更好的处理.水平滚动是由列边缘超出窗口的边界而不是列的内容触发的.因此,您可以使用这些参数将列强制变宽,从而强制滚动.

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天全站免登陆