如何在 Treeview 小部件中禁用列大小调整?

use*_*109 5 python treeview tkinter

我在 Python 中有一个非常基本的Treeview设置:

self.tv = ttk.Treeview(top_frame, columns=("#","ID","Name"), selectmode = "browse" )

self.tv.heading('#1', text='#', anchor=W)
self.tv.heading('#2', text='ID', anchor=W)
self.tv.heading('#3', text='Name', anchor=W)

self.tv.column('#1',minwidth=70, width = 70, stretch=NO)
self.tv.column('#2', minwidth = 240, width = 240, stretch=NO)
self.tv.column('#3', minwidth=260, width = 260, stretch=NO)
self.tv.column('#0', minwidth=0, width=0, stretch=NO)
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是可以调整列的大小以使树视图比其容器更宽或更窄。两者都破坏了整个事物的美感。

根据我的阅读,stretch = NO应该禁用此功能,但事实并非如此。我正在 Mac 上使用 Python 2.7.9 测试 GUI。我知道某些小部件在 Mac 上无法 100% 工作,那么我是否做错了什么,或者这就是我所期望的?

小智 0

在 Python ttk 中,column() 的拉伸参数采用 True/False。“stretch=False”在 OSX 上适用于我。请参阅https://docs.python.org/2/library/ttk.html#ttk.Treeview.column