如何在Python 3.3中更改ttk.Treeview列宽和重量

时间:2021-01-12 18:22:00

I have created a GUI for my application with Tkinter. I am using also a treeview widget. However I am unable to change its column widths and weights. How to do it properly?

我用Tkinter为我的应用程序创建了一个GUI。我也在使用树视图小部件。但是我无法更改其列宽和重量。怎么做得好?

Sample:

样品:

tree = Treeview(frames[-1],selectmode="extended",columns=("A","B"))
tree.heading("#0", text="C/C++ compiler")
tree.column("#0",minwidth=0,width=100)

tree.heading("A", text="A")   
tree.column("A",minwidth=0,width=200) 

tree.heading("B", text="B")   
tree.column("B",minwidth=0,width=300) 

As far as I understand it should create three columns with widths: 100,200 and 300. However nothing like that happens.

据我所知,它应该创建三个宽度为100,200和300的列。但是没有类似的情况发生。

1 个解决方案

#1


8  

Treeview.Column do not have weight option, but you can set stretch option to False to prevent column resizing.

Treeview.Column没有权重选项,但您可以将stretch选项设置为False以防止列大小调整。

from tkinter import *
from tkinter.ttk import *

root = Tk()
tree = Treeview(root,selectmode="extended",columns=("A","B"))
tree.pack(expand=YES, fill=BOTH)
tree.heading("#0", text="C/C++ compiler")
tree.column("#0",minwidth=0,width=100, stretch=NO)
tree.heading("A", text="A")   
tree.column("A",minwidth=0,width=200, stretch=NO) 
tree.heading("B", text="B")   
tree.column("B",minwidth=0,width=300)
root.mainloop()

#1


8  

Treeview.Column do not have weight option, but you can set stretch option to False to prevent column resizing.

Treeview.Column没有权重选项,但您可以将stretch选项设置为False以防止列大小调整。

from tkinter import *
from tkinter.ttk import *

root = Tk()
tree = Treeview(root,selectmode="extended",columns=("A","B"))
tree.pack(expand=YES, fill=BOTH)
tree.heading("#0", text="C/C++ compiler")
tree.column("#0",minwidth=0,width=100, stretch=NO)
tree.heading("A", text="A")   
tree.column("A",minwidth=0,width=200, stretch=NO) 
tree.heading("B", text="B")   
tree.column("B",minwidth=0,width=300)
root.mainloop()