gpt4 book ai didi

python - tkinter - ttk TreeView : see column text

转载 作者:太空宇宙 更新时间:2023-11-04 04:59:43 25 4
gpt4 key购买 nike

我正在使用 ttk 的 Treeview 小部件在 Tkinter 中构建一个表。但是,在我插入列后,它们会在没有文本的情况下显示。这是代码:

w=Tk()
f=Frame(w)
f.pack()
t=Treeview(f,columns=("Titolo","Data","Allegati?"))
t.pack(padx=10,pady=10)
t.insert("",1,text="Sample")

结果如下:

Treeview Result Image

我该如何解决?

谢谢

最佳答案

您需要为每一列定义标题。我不知道你是否想为标题使用相同的列名,所以这将是我的例子。您可以将文本更改为您想要的任何内容。要定义 header ,您需要像这样使用 heading():

t.heading("Titolo", text="Titolo")
t.heading("Data", text="Data")
t.heading("Allegati?", text="Allegati?")

通过这些更改,您的最终代码应如下所示:

from tkinter import *
from tkinter.ttk import *


w=Tk()

f = Frame(w)
f.pack()
t = Treeview(f, columns=("Titolo", "Data", "Allegati?"))

t.heading("Titolo", text="Titolo")
t.heading("Data", text="Data")
t.heading("Allegati?", text="Allegati?")

t.pack(padx=10, pady=10)
t.insert("", 1, text="Sample")

w.mainloop()

结果:

enter image description here

如果您有任何问题,请告诉我。

关于python - tkinter - ttk TreeView : see column text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46056822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com