我想禁用列的调整大小,但是我的python版本3.4.3没有工作,我不知道为什么。
from tkinter import *
from tkinter import ttk
def main():
gMaster = Tk()
w = ttk.Treeview(gMaster, show="headings", columns=('Column1', 'Column2'))
w.heading('#1', text='Column1', anchor=W)
w.heading('#2', text='Column2', anchor=W)
w.column('#1', minwidth = 70, width = 70, stretch = False)
w.column('#2', minwidth = 70, width = 70, stretch = False)
w.grid(row = 0, column = 0)
mainloop()
if __name__ == "__main__":
main()发布于 2016-04-12 01:04:38
下面是一个带有评论的演示。尝试更改拉伸值和更改应用程序窗口的宽度,您将看到差异。也许没有必要阻止用户调整列的大小。相反,更重要的是,给每一列一个适当的初始宽度,以便它的内容可以轻松地显示。
from tkinter import *
from tkinter import ttk
def main():
gMaster = Tk()
w = ttk.Treeview(gMaster, show="headings", columns=('Column1', 'Column2'))
w.heading('#1', text='Column1', anchor=W)
w.heading('#2', text='Column2', anchor=W)
w.column('#1', minwidth = 70, width = 70, stretch = False)
w.column('#2', minwidth = 70, width = 70, stretch = True) # Try to change the value of stretch here.
# The following 2 lines will make the Treeview `w` fill the window horizontally.
w.grid(row = 0, column = 0, sticky='we')
gMaster.grid_columnconfigure(0, weight=1)
mainloop()
if __name__ == "__main__":
# Try to change the width of the application window use your mouse and you will see
# the width of column #2 will:
# 1. keep unchanged when strech=False
# 2. change when strech=True
main()发布于 2021-06-09 01:55:20
若要禁用列大小调整,需要创建一个def,以便在分隔符x和y中停止单击。
def handle_click(event):
if treeview.identify_region(event.x, event.y) == "separator":
return "break"
#...
treeview.bind('<Button-1>', handle_click)我希望我能帮助每个需要解决这个问题的人。对不起,英语不好,这不是我的第一语言。
发布于 2016-04-11 11:32:51
尝试在mainloop()之前添加以下内容
gMaster.resizable(0,0)你不需要拉伸=假
https://stackoverflow.com/questions/36547190
复制相似问题