ttk::treeview − hierarchical multicolumn data display widget


ttk::treeview pathname ?options? ___________________________


The ttk::treeview widget displays a hierarchical collection of items. Each item has a textual label, an optional image, and an optional list of data values. The data values are displayed in successive columns after the tree label.

The order in which data values are displayed may be controlled by setting the −displaycolumns widget option. The tree widget can also display column headings. Columns may be accessed by number or by symbolic names listed in the −columns widget option; see COLUMN IDENTIFIERS.

Each item is identified by a unique name. The widget will generate item IDs if they are not supplied by the caller. There is a distinguished root item, named {}. The root item itself is not displayed; its children appear at the top level of the hierarchy.

Each item also has a list of tags, which can be used to associate event bindings with individual items and control the appearance of the item.

Treeview widgets support horizontal and vertical scrolling with the standard [xy]scrollcommand options and [xy]view widget commands.








See the ttk_widget manual entry for details on the standard options.


Command-Line Name:−columns

Database Name:


Database Class:


A list of column identifiers, specifying the number of columns and their names.

Command-Line Name:−displaycolumns

Database Name:


Database Class:


A list of column identifiers (either symbolic names or integer indices) specifying which data columns are displayed and the order in which they appear, or the string #all. If set to #all (the default), all columns are shown in the order given.

Command-Line Name:−height

Database Name:


Database Class:


Specifies the number of rows which should be visible. Note: the requested width is determined from the sum of the column widths.

Command-Line Name:−padding

Database Name:


Database Class:


Specifies the internal padding for the widget. The padding is a list of up to four length specifications; see Ttk_GetPaddingFromObj() for details.

Command-Line Name:−selectmode

Database Name:


Database Class:


Controls how the built-in class bindings manage the selection. One of extended, browse, or none.

If set to extended (the default), multiple items may be selected. If browse, only a single item will be selected at a time. If none, the selection will not be changed.

Note that application code and tag bindings can set the selection however they wish, regardless of the value of −selectmode.

Command-Line Name:−show

Database Name:


Database Class:


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


Display tree labels in column #0.


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.


pathname bbox item ?column?

Returns the bounding box (relative to the treeview widget’s window) of the specified item in the form x y width height. If column is specified, returns the bounding box of that cell. If the item is not visible (i.e., if it is a descendant of a closed item or is scrolled offscreen), returns the empty list.

pathname cget option

Returns the current value of the specified option; see ttk::widget(n).

pathname children item ?newchildren?

If newchildren is not specified, returns the list of children belonging to item.

If newchildren is specified, replaces item’s child list with newchildren. Items in the old child list not present in the new child list are detached from the tree. None of the items in newchildren may be an ancestor of item.

pathname column column ?−option ?value −option value...?

Query or modify the options for the specified column. If no −option is specified, returns a dictionary of option/value pairs. If a single −option is specified, returns the value of that option. Otherwise, the options are updated with the specified values. The following options may be set on each column:

The column name. This is a read-only option. For example, [$pathname column #n −id] returns the data column associated with display column #n.


Specifies how the text in this column should be aligned with respect to the cell. One of n, ne, e, se, s, sw, w, nw, or center.


The minimum width of the column in pixels. The treeview widget will not make the column any smaller than −minwidth when the widget is resized or the user drags a column separator.


Specifies whether or not the column’s width should be adjusted when the widget is resized.

−width w

The width of the column in pixels. Default is something reasonable, probably 200 or so.

Use pathname column #0 to configure the tree column.

pathname configure ?option? ?value option value ...?

Modify or query widget options; see ttk::widget(n).

pathname delete itemList

Deletes each of the items in itemList and all of their descendants. The root item may not be deleted. See also: detach.

pathname detach itemList

Unlinks all of the specified items in itemList from the tree. The items and all of their descendants are still present and may be reinserted at another point in the tree with the move operation, but will not be displayed until that is done. The root item may not be detached. See also: delete.

pathname exists item

Returns 1 if the specified item is present in the tree, 0 otherwise.

pathname focus ?item?

If item is specified, sets the focus item to item. Otherwise, returns the current focus item, or {} if there is none.

pathname heading column ?−option ?value −option value...?

Query or modify the heading options for the specified column. Valid options are:

The text to display in the column heading.

−image imageName

Specifies an image to display to the right of the column heading.

−anchor anchor

Specifies how the heading text should be aligned. One of the standard Tk anchor values.

−command script

A script to evaluate when the heading label is pressed.

Use pathname heading #0 to configure the tree column heading.

pathname identify component x y

Returns a description of the specified component under the point given by x and y, or the empty string if no such component is present at that position. The following subcommands are supported:
identify region x y

Returns one of:

Tree heading area; use [pathname identify column x y] to determine the heading number.


Space between two column headings; [pathname identify column x y] will return the display column identifier of the heading to left of the separator.


The tree area.


A data cell.

pathname identify item x y Returns the item ID of the item at position y.
identify column x y

Returns the data column identifier of the cell at position x. The tree column has ID #0.

pathname identify element x y

The element at position x,y.

pathname identify row x y

Obsolescent synonym for pathname identify item.

See COLUMN IDENTIFIERS for a discussion of display columns and data columns.

pathname index item

Returns the integer index of item within its parent’s list of children.

pathname insert parent index ?−id id? options...

Creates a new item. parent is the item ID of the parent item, or the empty string {} to create a new top-level item. index is an integer, or the value end, specifying where in the list of parent’s children to insert the new item. If index is less than or equal to zero, the new node is inserted at the beginning; if index is greater than or equal to the current number of children, it is inserted at the end. If −id is specified, it is used as the item identifier; id must not already exist in the tree. Otherwise, a new unique identifier is generated.

pathname insert returns the item identifier of the newly created item. See ITEM OPTIONS for the list of available options.

pathname instate statespec ?script?

Test the widget state; see ttk::widget(n).

pathname item item ?−option ?value −option value...?

Query or modify the options for the specified item. If no −option is specified, returns a dictionary of option/value pairs. If a single −option is specified, returns the value of that option. Otherwise, the item’s options are updated with the specified values. See ITEM OPTIONS for the list of available options.

pathname move item parent index

Moves item to position index in parent’s list of children. It is illegal to move an item under one of its descendants.

If index is less than or equal to zero, item is moved to the beginning; if greater than or equal to the number of children, it is moved to the end.

pathname next item

Returns the identifier of item’s next sibling, or {} if item is the last child of its parent.

pathname parent item

Returns the ID of the parent of item, or {} if item is at the top level of the hierarchy.

pathname prev item

Returns the identifier of item’s previous sibling, or {} if item is the first child of its parent.

pathname see item

Ensure that item is visible: sets all of item’s ancestors to −open true, and scrolls the widget if necessary so that item is within the visible portion of the tree.

pathname selection ?selop itemList?

If selop is not specified, returns the list of selected items. Otherwise, selop is one of the following:
selection set itemList

itemList becomes the new selection.

pathname selection add itemList

Add itemList to the selection

pathname selection remove itemList

Remove itemList from the selection

pathname selection toggle itemList

Toggle the selection state of each item in itemList.

pathname set item ?column? ?value?

With one argument, returns a dictionary of column/value pairs for the specified item. With two arguments, returns the current value of the specified column. With three arguments, sets the value of column column in item item to the specified value. See also COLUMN IDENTIFIERS.

pathname state ?stateSpec?

Modify or query the widget state; see ttk::widget(n).

pathName tag args...

pathName tag bind tagName ?sequence? ?script?

Add a Tk binding script for the event sequence sequence to the tag tagName. When an X event is delivered to an item, binding scripts for each of the item’s −tags are evaluated in order as per bindtags(n).

<KeyPress>, <KeyRelease>, and virtual events are sent to the focus item. <ButtonPress>, <ButtonRelease>, and <Motion> events are sent to the item under the mouse pointer. No other event types are supported.

The binding script undergoes %-substitutions before evaluation; see bind(2) for details.

pathName tag configure tagName ?option? ?value option value...?

Query or modify the options for the specified tagName. If one or more option/value pairs are specified, sets the value of those options for the specified tag. If a single option is specified, returns the value of that option (or the empty string if the option has not been specified for tagName). With no additional arguments, returns a dictionary of the option settings for tagName. See TAG OPTIONS for the list of available options.

pathName tag has tagName ?item?

If item is specified, returns 1 or 0 depending on whether the specified item has the named tag. Otherwise, returns a list of all items which have the specified tag.

pathName tag names

Returns a list of all tags used by the widget.

pathName tag add tag items

Adds the specified tag to each of the listed items. If tag is already present for a particular item, then the −tags for that item are unchanged.

pathName tag remove tag ?items?

Removes the specified tag from each of the listed items. If items is omitted, removes tag from each item in the tree. If tag is not present for a particular item, then the −tags for that item are unchanged.

pathName xview args

Standard command for horizontal scrolling; see widget(n).

pathName yview args

Standard command for vertical scrolling; see ttk::widget(n).


The following item options may be specified for items in the insert and item widget commands.

Command-Line Name:−text

Database Name:


Database Class:


The textual label to display for the item.

Command-Line Name:−image

Database Name:


Database Class:


A Tk image, displayed to the left of the label.

Command-Line Name:−values

Database Name:


Database Class:


The list of values associated with the item.

Each item should have the same number of values as the −columns widget option. If there are fewer values than columns, the remaining values are assumed empty. If there are more values than columns, the extra values are ignored.

Command-Line Name:−open

Database Name:


Database Class:


A boolean value indicating whether the item’s children should be displayed (−open true) or hidden (−open false).

Command-Line Name:−tags

Database Name:


Database Class:


A list of tags associated with this item.


The following options may be specified on tags:

Specifies the text foreground color.


Specifies the cell or item background color.


Specifies the font to use when drawing text.


Specifies the item image, in case the item’s −image option is empty.


Column identifiers take any of the following forms:

A symbolic name from the list of −columns.

An integer n, specifying the nth data column.

A string of the form #n, where n is an integer, specifying the nth display column.

NOTE: Item −values may be displayed in a different order than the order in which they are stored.

NOTE: Column #0 always refers to the tree column, even if −show tree is not specified.

A data column number is an index into an item’s −values list; a display column number is the column number in the tree where the values are displayed. Tree labels are displayed in column #0. If −displaycolumns is not set, then data column n is displayed in display column #n+1. Again, column #0 always refers to the tree column.


The treeview widget generates the following virtual events.

Generated whenever the selection changes.


Generated just before setting the focus item to −open true.


Generated just after setting the focus item to −open false.

The focus and selection widget commands can be used to determine the affected item or items.


ttk::widget(n), listbox(n), image(n), bind(2)


Personal Opportunity - Free software gives you access to billions of dollars of software at no cost. Use this software for your business, personal use or to develop a profitable skill. Access to source code provides access to a level of capabilities/information that companies protect though copyrights. Open source is a core component of the Internet and it is available to you. Leverage the billions of dollars in resources and capabilities to build a career, establish a business or change the world. The potential is endless for those who understand the opportunity.

Business Opportunity - Goldman Sachs, IBM and countless large corporations are leveraging open source to reduce costs, develop products and increase their bottom lines. Learn what these companies know about open source and how open source can give you the advantage.

Free Software

Free Software provides computer programs and capabilities at no cost but more importantly, it provides the freedom to run, edit, contribute to, and share the software. The importance of free software is a matter of access, not price. Software at no cost is a benefit but ownership rights to the software and source code is far more significant.

Free Office Software - The Libre Office suite provides top desktop productivity tools for free. This includes, a word processor, spreadsheet, presentation engine, drawing and flowcharting, database and math applications. Libre Office is available for Linux or Windows.

Free Books

The Free Books Library is a collection of thousands of the most popular public domain books in an online readable format. The collection includes great classical literature and more recent works where the U.S. copyright has expired. These books are yours to read and use without restrictions.

Source Code - Want to change a program or know how it works? Open Source provides the source code for its programs so that anyone can use, modify or learn how to write those programs themselves. Visit the GNU source code repositories to download the source.


Study at Harvard, Stanford or MIT - Open edX provides free online courses from Harvard, MIT, Columbia, UC Berkeley and other top Universities. Hundreds of courses for almost all major subjects and course levels. Open edx also offers some paid courses and selected certifications.

Linux Manual Pages - A man or manual page is a form of software documentation found on Linux/Unix operating systems. Topics covered include computer programs (including library and system calls), formal standards and conventions, and even abstract concepts.