Remove header row in tkinter treeview

我怕爱的太早我们不能终老 提交于 2020-04-14 19:25:29

问题


Can anyone tell me how to remove the header row in a tkinter Treeview?

from tkinter import *
from tkinter import ttk

root = Tk()

NewTree= ttk.Treeview(root)
NewTree.pack()
NewTree.heading("#0", text="How to remove this row?")
NewTree.insert("", "0", 'item1',text='Item number 1')

root.mainloop()

回答1:


Use the show option to only show the tree and not the heading:

NewTree = ttk.Treeview(root, show="tree")

Relevant documentation

From docs.python.org:

show

A list containing zero or more of the following values, specifying which elements of the tree to display.

  • tree: display tree labels in column #0.
  • headings: display the heading row.

The default is “tree headings”, i.e., show all elements.

Note: Column #0 always refers to the tree column, even if show=”tree” is not specified.

From the New Mexico Tech Tkinter reference:

show

To suppress the labels at the top of each column, specify show='tree'. The default is to show the column labels.

From TkDocs:

You can optionally hide one or both of the column headings or the tree itself (leaving just the columns) using the show widget configuration option (default is "tree headings" to show both).



来源:https://stackoverflow.com/questions/51762835/remove-header-row-in-tkinter-treeview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!