Treeview#
Treeview is the native ttk multi-column tree/table of items
(ttk.Treeview), themed by ttkbootstrap. This page is the complete
reference for its options, methods, and styling.
Options#
Each option can be set in the constructor and changed later with configure().
Option |
Type |
Description |
|---|---|---|
|
|
Constructor keyword. An accent color, optionally with a variant. See Styling options for the available styles. |
|
|
The identifiers of the data columns, beyond the implicit tree column. |
|
|
Which columns to display, and in what order (or |
|
|
Which parts to show: |
|
|
|
|
|
The number of rows visible before scrolling. |
|
|
Extra space around the contents, in pixels (a single value, or per-side). |
|
|
A callback connecting the tree to a horizontal scrollbar. |
|
|
A callback connecting the tree to a vertical scrollbar. |
|
|
The mouse cursor over the tree (see Cursors). |
|
|
Whether the tree accepts keyboard focus during traversal. |
Methods#
Items are addressed by a string iid. The tree column is "#0"; data
columns are addressed by name or by position as "#N".
Items#
- insert(parent, index, iid=None, **kw)
Insert an item under
parentatindex.kwincludestext,values,image,open, andtags.- Returns:
the new item’s iid.
- Return type:
- delete(*items)
Delete the given items (and their descendants).
- Returns:
None.
- item(item, option=None, **kw)
Query or set an item’s options.
- set(item, column=None, value=None)
Get or set the value of one cell.
- exists(item)
Return whether
itemis present in the tree.- Return type:
- see(item)
Open and scroll the tree so
itemis visible.- Returns:
None.
Structure#
- get_children(item=None)
Return the ids of
item’s children (default: the roots).- Return type:
- set_children(item, *newchildren)
Replace
item’s children withnewchildren.- Returns:
None.
- parent(item)
Return the id of
item’s parent (empty string for a root item).- Return type:
- index(item)
Return
item’s position among its siblings.- Return type:
- next(item)
Return the id of
item’s next sibling.- Return type:
- prev(item)
Return the id of
item’s previous sibling.- Return type:
- move(item, parent, index)
Move
itemto a newparentatindex.- Returns:
None.
- detach(*items)
Remove items from the tree display without deleting them.
- Returns:
None.
- reattach(item, parent, index)
Re-insert a previously detached item.
- Returns:
None.
Selection#
- selection()
Return the ids of the currently selected items.
- Return type:
- selection_set(*items)
Replace the selection with
items.- Returns:
None.
- selection_add(*items)
Add
itemsto the selection.- Returns:
None.
- selection_remove(*items)
Remove
itemsfrom the selection.- Returns:
None.
- selection_toggle(*items)
Toggle whether each of
itemsis selected.- Returns:
None.
Columns and headings#
- column(column, option=None, **kw)
Query or set a column’s options —
width,minwidth,anchor, andstretch.
- heading(column, option=None, **kw)
Query or set a heading’s
text,image,anchor, andcommand.
- identify_region(x, y)
Return which region of the treeview is under the pixel coordinate
(x, y)— e.g."heading","cell","tree", or"separator". Related methods narrow to one axis or element:identify_column(x),identify_row(y), andidentify_element(x, y).- Return type:
Scrolling#
- xview(*args)
Query or set the horizontal view; usually wired to a scrollbar. Has
xview_moveto(fraction)andxview_scroll(number, what)variants.
- yview(*args)
Query or set the vertical view; usually wired to a scrollbar. Has
yview_moveto(fraction)andyview_scroll(number, what)variants.
Styling options#
This section is for changing how the treeview looks. Define a style with
style.configure(...) (and style.map(...) for per-state colors), then
apply it with Treeview(style=...).
Bootstyle mapping#
Any of the accent colors – primary, secondary, success, info, warning, danger, light, dark – substitutes for primary below. neutral does not apply to this family.
|
ttk style name |
|---|---|
|
|
Layout (elements)#
The widget is drawn from these nested parts. Each is an element you can target by name in a custom layout:
Button.border
Treeview.padding
Treeview.treearea
Configurable style options#
Options you can set with style.configure(...) / style.map(...):
background, bordercolor, borderwidth, darkcolor, foreground, lightcolor, padding, relief, shiftrelief
Supported states#
The states you can target with style.map(...) to vary appearance by interaction:
disabled, selected
Hand-styling example#
import ttkbootstrap as ttk
app = ttk.App()
style = app.style
style.configure("my.Treeview", background="#3498db", foreground="white")
ttk.Treeview(app, style="my.Treeview").pack(padx=8, pady=8)
app.mainloop()
See also#
Treeview catalog page — usage, screenshots, and examples.
Tk ttk::treeview manual page — the canonical upstream reference (Tcl 8.6).