Tkinter / Python Treeview更改标题(Tkinter/Python Treeview change header)

我在使用树视图时遇到问题。 我需要一个列表框,可以有多个列,可以显示从SQL数据库收集的数据。 我的问题是树视图是第一个列名,不能改变。

table = ttk.Treeview(frame2, columns=['widgets']) table.heading('widgets', text='Item') table.pack()

你会想象到这一点,会创建一列树视图,然后重新将标题重命名为项目。 它创建了两列,最后一列称为item,第一列为空。

有没有办法改变第一个comlumn的名字,或者有更好的方法来做到这一点?

I'm having a problem using the treeview. I need a listbox, that can have multiple columns, that i can display data, collected from a SQL database. My problem with the treeview is that is first column name, can't be changed.

table = ttk.Treeview(frame2, columns=['widgets']) table.heading('widgets', text='Item') table.pack()

You would imagin that this, would create a treeview with one column, and then rename the header to item. It creates two columns where the last one is called item and the first empty.

Is there a way to change the first comlumn name or is there a better way doing this?

最满意答案

使用列标识符"#0"更改树列的标题:

table.heading('#0', text='Name')

Use the column identifier "#0" to change the heading of the tree column:

table.heading('#0', text='Name')

更多推荐