【问题标题】:How to change ttk.Treeview column width and weight in Python 3.3如何在 Python 3.3 中更改 ttk.Treeview 列宽和粗细
【发布时间】:2013-05-04 16:54:06
【问题描述】:

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

示例:

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) 

据我了解,它应该创建三列宽度:100,200 和 300。 然而,不会发生这样的事情。

【问题讨论】:

  • 然后会发生什么?这段代码对我有用。
  • 每一列的宽度相同。
  • 你能发布最小的工作示例(不是一段代码)吗?
  • 再次配置python解释器后,它工作正常。但是如何设置权重,以便在调整某些列的大小时不改变大小?

标签: python python-3.x tkinter


【解决方案1】:

Treeview.Column 没有weight 选项,但您可以将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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-23
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 2011-05-08
    • 2020-08-23
    相关资源
    最近更新 更多