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

Python 如何在Treeview小部件中禁用列大小调整?,python,tkinter,treeview,Python,Tkinter,Treeview,我在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

我在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)
我遇到的问题是,可以调整列的大小,使treeview比其容器更宽,或者更窄。这两件事都破坏了整件事的美感

据我所知,
stretch=NO
应该禁用此功能,但它不是。我正在用Python2.7.9在Mac上测试GUI。我知道某些小部件无法在Mac上100%正常工作,所以我是否做错了什么,或者这就是我所能期望的?

column()的拉伸参数在Python ttk中为True/False。“stretch=False”在OSX上适用于我。
请参见

要禁用列大小调整,您需要创建一个def,以在其位于分隔符x和y中时中断单击。请参见示例:

def handle_click(event):
    if treeview.identify_region(event.x, event.y) == "separator":
        return "break"
    
    #...


treeview.bind('<Button-1>', handle_click)
def handle_单击(事件):
如果treeview.identify_区域(event.x,event.y)=“分隔符”:
返回“中断”
#...
treeview.bind(“”,句柄\单击)
我希望我能帮助所有需要解决这个问题的人。

(对于未来的读者)当
事件通过树状视图分隔符时,我可以捕获并阻止它,因为我概述了一个明显重复的问题。