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.
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.
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.
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.
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.
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 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. Default is 20 pixels.
Specifies whether or not the column width should be adjusted
when the widget is resized or the user drags a column separator.
Boolean may have any of the forms accepted by Tcl_GetBoolean.
By default columns are stretchable.
The width of the column in pixels. Default is 200 pixels. The specified
column width may be changed by Tk in order to honor -stretch
and/or -minwidth, or when the widget is resized or the user drags a
column separator.
Use pathname column #0 to configure the tree column.
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.
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:
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.
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.
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.
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.
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(n) for details.
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.
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.
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.
The treeview widget also supports the following generic ttk::widget
widget subcommands (see ttk::widget(n) for details):
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.
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 class name for a ttk::treeview is Treeview.
The treeview header class name is Heading.
The treeview item class name is Item.
The treeview cell class name is Cell.
Dynamic states: disabled, selected.
Treeview styling options configurable with ttk::style
are:
The -rowheight value is not corrected by the tk scaling
value or by the configured font size and must always be set. Also make
sure that the -rowheight is large enough to contain any images.
To adjust the -rowheight for the Treeview style, use the following code
after tk scaling has been applied.
Note that even if you do not support or change tk scaling
in your program, your users may have it set in their .wishrc.