2017-09-05 118 views
1

我正在Tkinter中使用ttk的Treeview小部件构建表格。但是,在插入列后,它们显示为没有文本。 下面是代码:python 3 - tkinter - ttk treeview:查看列文本

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

我该如何解决?

谢谢

+0

可能相关:https://stackoverflow.com/questions/36120426/tkinter-treeview-widget-inserting-data – Lafexlos

回答

0

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

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

设我知道你是否有任何问题。

+0

谢谢,如果我想添加数据到列中,我该怎么做? –

+0

@MaicolBatti对于很多你需要的treeview方法,可能在这里使用'insert()'是[doc page](http://www.tkdocs.com/tutorial/tree.html)。 –