[英]tkinter - ttk treeview: see column text
我正在使用 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()
结果:
如果您有任何问题,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.