Tk - Treeview Widget


Treeview widget is used to choose a numeric value through sliders. The syntax for treeview widget is shown below.

treeview treeviewName options


The options available for the treeview widget are listed below in table.

Sr.No. Syntax & Description

-columns columnNames

An array of column names for widget.


-displaycolumns columns

An array of column names or indices specifying columns to be displayed. Use #all for all.


-height number

Height for widget.


-selectmode mode

Selection mode which can be extended, browse, or none.

A simple example for treeview widget is shown below.


ttk::treeview .tree -columns "Creator Year" -displaycolumns "Year Creator" 
.tree heading Creator -text "Creator" -anchor center
.tree heading Year -text "Year" -anchor center
pack .tree
.tree insert {} end -id Languages -text "Languages"
.tree insert Languages end -text C -values [list "Dennis Ritchie" "1990"]
.tree insert "" end -id Direct -text "Direct"   

When we run the above program, we will get the following output.

Treeview Widget

To move the elements, we can use the following command.

.tree move Languages Direct end

We will get the following output when the above command is executed.

Treeview Widget2

Similarly, we can use the delete command to delete a values from treeview.