简体   繁体   中英

tkinter - ttk treeview: see column text

I'm building a table in Tkinter using ttk's Treeview widget. However, after I inserted the columns they display it without text. Here is the code:

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")

Here the result:

树状视图结果图像

How can I solve?

Thanks

You need to define the headers for each column. I don't know if you want to use the same column names for the header or not so that is going to be my example. You can change the text to whatever you want. To define the header you will need to use heading() like this:

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

With those changes your final code should look like this:

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()

Results:

在此处输入图片说明

Let me know if you have any questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM