tkinter ttk treeview:见tex列

2024-06-25 22:45:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用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

我怎么解决?在

谢谢


Tags: columns代码文本data部件tkinterframepack
1条回答
网友
1楼 · 发布于 2024-06-25 22:45:45

您需要为每个列定义标题。我不知道你是否想在标题中使用相同的列名,这就是我的例子。你可以把文本改成任何你想要的。要定义标题,您需要使用heading(),如下所示:

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

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

^{pr2}$

结果:

enter image description here

如果你有任何问题请告诉我。在

相关问题 更多 >