treeview -
hierarchical multicolumn data display widget
ttk::treeview pathname ?options?
The 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.
Treeview widgets support vertical scrolling with the
standard -yscrollcommand option and yview widget command.
They probably ought to support horizontal scrolling as well.
Name | Database name | Database class |
-columns | columns | Columns |
| A list of column identifiers,
specifying the number of columns and their names.
|
-displaycolumns | displayColumns | DisplayColumns |
| A list of column identifiers
(either symbolic names or integer indices)
specifying which data columns are displayed
and the order in which they appear.
If empty (the default), all columns are shown in the order given.
|
-height | height | Height |
| Specifies the number of rows which should be visible.
Note:
the requested width is determined from the sum of the column widths.
|
-padding | padding | Padding |
| Specifies the internal padding for the widget.
The padding is a list of up to four length specifications;
see Ttk_GetPaddingFromObj() for details.
|
-show | show | 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.
|
-
pathname cget option
- Returns the current value of the specified option; see 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:
-
-id name
- The column name. This is a read-only option.
For example, [$pathname column #n -id]
returns the data column associated with data column #n.
- -anchor
- 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.
-
-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 widget(n).
-
pathname delete items
- Deletes each of the items and all of their descendants.
The root item may not be deleted.
See also: detach.
-
pathname detach items
- Unlinks all of the specified items from the tree.
The items and all of their descendants are still present
and may be reinserted at another point in the tree
but will not be displayed.
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:
-
-text text
- The text to display in the column heading.
-
-image imageName
- Specifies an image to display to the right of the column heading.
-
-command script
- A script to evaluate when the heading label is pressed.
Use pathname heading #0 to configure the tree column heading.
-
pathname identify x y
- Returns a description of the widget component under the point given by
x and y. The return value is a list with one of the
following forms:
-
heading #n
- The column heading for display column #n.
-
separator #n
- The border to the right of display column #n.
-
cell itemid #n
- The data value for item itemid in display column #n.
-
item itemid element
- The tree label for item itemid; element is one
of text, image, or indicator, or another element name
depending on the style.
-
row itemid
- The y position is over the item but
x does not identify any element or displayed data value.
- nothing
- The coordinates are not over any identifiable object.
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 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's 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 items?
- If selop is not specified, returns the list of selected items.
Otherwise, selop is one of the following:
-
pathname selection set items
-
items becomes the new selection.
-
pathname selection add items
- Add items to the selection
-
pathname selection remove items
- Remove items from the selection
-
pathname selection toggle items
- Toggle the selection state of each item in items.
-
pathname set item column ?value?
- If value is specified, sets the value of column column
in item item, otherwise returns the current value.
See COLUMN IDENTIFIERS.
-
pathname state ?stateSpec?
- Modify or query the widget state; see widget(n).
-
pathName yview args
- Standard command for vertical scrolling; see widget(n).
The following item options may be specified for items
in the insert and item widget commands.
Name | Database name | Database class |
-text | text | Text |
| The textual label to display for the item.
|
-image | image | Image |
| A Tk image, displayed to the left of the label.
|
-values | values | Values |
| 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.
|
-open | open | Open |
| A boolean value indicating whether the items's children
should be displayed (-open true) or hidden (-open false).
|
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.
- <<TreeviewSelect>>
- Generated whenever the selection changes.
- <<TreeviewOpen>>
- Generated just before setting the focus item to -open true.
- <<TreeviewClose>>
- 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.
In Tk 8.5, the affected item is also passed as the -detail field
of the virtual event.
widget(n), listbox(n), image(n)