Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove header row in tkinter treeview

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()
like image 747
Tola Avatar asked Aug 09 '18 08:08

Tola


People also ask

How do you delete all rows in Treeview?

If we want to remove or clear all the items in a given treeview widget, then we have to first select all the items present in the treeview widget using get_children() method. Once we have selected all the treeview items programmatically, then we can delete the items using delete(item) method.

How do I edit a Treeview in Python?

The Treeview widget items can be edited and deleted by selecting the item using tree. selection() function. Once an item is selected, we can perform certain operations to delete or edit the item.

How do I disable Treeview in Python?

The Treeview widget is used to display a list of items with more than one feature in the form of columns. By default, the listed items in a Treeview widget can be selected multiple times, however you can disable this feature by using selectmode="browse" in the Treeview widget constructor.

What is IID in tkinter Treeview?

The iid argument stands for item identifier which is unique for each item, and you can give it the value you want.


1 Answers

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

like image 53
fhdrsdg Avatar answered Oct 10 '22 03:10

fhdrsdg