Skip to content

Tree node

TreeNode

Bases: Generic[TreeDataType]

An object that represents a "node" in a tree control.

allow_expand: bool writable property

children: TreeNodes[TreeDataType] property

TreeNodes[TreeDataType]: The child nodes of a TreeNode.

id: NodeID property

is_expanded: bool property

is_last: bool property

label: TextType writable property

line: int property

parent: TreeNode[TreeDataType] | None property

TreeNode[TreeDataType] | None: The parent of the node.

add(label, data=None, *, expand=False, allow_expand=True)

Add a node to the sub-tree.

Parameters:

Name Type Description Default
label TextType

The new node's label.

required
data TreeDataType | None

Data associated with the new node.

None
expand bool

Node should be expanded. Defaults to True.

False
allow_expand bool

Allow use to expand the node via keyboard or mouse. Defaults to True.

True

Returns:

Type Description
TreeNode[TreeDataType]

A new Tree node

add_leaf(label, data=None)

Add a 'leaf' node (a node that can not expand).

Parameters:

Name Type Description Default
label TextType

Label for the node.

required
data TreeDataType | None

Optional data. Defaults to None.

None

Returns:

Type Description
TreeNode[TreeDataType]

New node.

collapse()

Collapse the node (hide children).

expand()

Expand a node (show its children).

set_label(label)

Set a new label for the node.

Parameters:

Name Type Description Default
label TextType

A str or Text object with the new label.

required

toggle()

Toggle the expanded state.