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

bootstyle

str

Constructor keyword. An accent color, optionally with a variant. See Styling options for the available styles.

columns

list

The identifiers of the data columns, beyond the implicit tree column.

displaycolumns

list

Which columns to display, and in what order (or "#all").

show

str

Which parts to show: "tree", "headings", or both.

selectmode

str

"extended", "browse", or "none".

height

int

The number of rows visible before scrolling.

padding

int | tuple

Extra space around the contents, in pixels (a single value, or per-side).

xscrollcommand

callable

A callback connecting the tree to a horizontal scrollbar.

yscrollcommand

callable

A callback connecting the tree to a vertical scrollbar.

cursor

str

The mouse cursor over the tree (see Cursors).

takefocus

bool

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 parent at index. kw includes text, values, image, open, and tags.

Returns:

the new item’s iid.

Return type:

str

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 item is present in the tree.

Return type:

bool

see(item)

Open and scroll the tree so item is visible.

Returns:

None.

Structure#

get_children(item=None)

Return the ids of item’s children (default: the roots).

Return type:

tuple

set_children(item, *newchildren)

Replace item’s children with newchildren.

Returns:

None.

parent(item)

Return the id of item’s parent (empty string for a root item).

Return type:

str

index(item)

Return item’s position among its siblings.

Return type:

int

next(item)

Return the id of item’s next sibling.

Return type:

str

prev(item)

Return the id of item’s previous sibling.

Return type:

str

move(item, parent, index)

Move item to a new parent at index.

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:

tuple

selection_set(*items)

Replace the selection with items.

Returns:

None.

selection_add(*items)

Add items to the selection.

Returns:

None.

selection_remove(*items)

Remove items from the selection.

Returns:

None.

selection_toggle(*items)

Toggle whether each of items is selected.

Returns:

None.

Columns and headings#

column(column, option=None, **kw)

Query or set a column’s options — width, minwidth, anchor, and stretch.

heading(column, option=None, **kw)

Query or set a heading’s text, image, anchor, and command.

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), and identify_element(x, y).

Return type:

str

Tags#

tag_configure(tagname, option=None, **kw)

Query or set display options (e.g. foreground, background) applied to items carrying tagname.

tag_bind(tagname, sequence=None, callback=None)

Bind an event sequence to items carrying tagname.

tag_has(tagname, item=None)

Return whether item carries tagname, or (if item is omitted) all items that do.

Return type:

bool or tuple

Scrolling#

xview(*args)

Query or set the horizontal view; usually wired to a scrollbar. Has xview_moveto(fraction) and xview_scroll(number, what) variants.

yview(*args)

Query or set the vertical view; usually wired to a scrollbar. Has yview_moveto(fraction) and yview_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.

bootstyle

ttk style name

primary

primary.Treeview

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()

Shared capabilities#

Treeview also has the methods every widget inherits — configuration, placement, event binding, lifecycle, focus, and introspection — plus the ttk state methods state / instate / identify. These are documented under Capabilities.

See also#