我正在使用 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")
结果如下:
如何解决?
谢谢
最佳答案
您需要定义每列的标题。我不知道您是否想对标题使用相同的列名称,所以这将是我的示例。您可以将文本更改为您想要的任何内容。要定义标题,您需要使用 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()
结果:
如果您有任何疑问,请告诉我。
关于python - tkinter - ttk TreeView : see column text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46056822/