Skip to content
Discussion options

You must be logged in to vote

You might find the code references in the docs for Tree and TreeNode helpful.

select_node will only "Move the cursor to the given node". You can change the expanded state of a TreeNode using the toggle or expand methods.

EDIT: It looks like you could also use action_toggle_node, but only after ensuring that the selected node has refreshed: tree.call_after_refresh(tree.action_toggle_node)

from textual.app import App, ComposeResult
from textual.widgets import Tree


class TreeApp(App):
    def compose(self) -> ComposeResult:
        tree: Tree[dict] = Tree("Dune")
        tree.root.expand()
        characters = tree.root.add("Characters")
        characters.add_leaf("Paul")
        characters.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@TomJGooding
Comment options

Answer selected by davep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants