簡體   English   中英

tkinter - ttk 樹視圖:查看列文本

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM