【问题标题】:tkinter - ttk treeview: see column texttkinter - ttk 树视图:查看列文本
【发布时间】:2018-02-13 20:36:40
【问题描述】:

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

结果如下:

我该如何解决?

谢谢

【问题讨论】:

标签: python python-3.x tkinter treeview ttk


【解决方案1】:

您需要为每列定义标题。我不知道你是否想对标题使用相同的列名,所以这将是我的例子。您可以将文本更改为您想要的任何内容。要定义标题,您需要像这样使用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()

结果:

如果您有任何问题,请告诉我。

【讨论】:

  • 谢谢,如果我想将数据添加到列中,我该怎么做?
  • t.insert("", 1, text="Sample", values=(1,2))
猜你喜欢
  • 2017-02-06
  • 2018-12-30
  • 1970-01-01
  • 1970-01-01
  • 2011-12-15
  • 1970-01-01
  • 1970-01-01
  • 2020-07-09
  • 2019-02-03
相关资源
最近更新 更多