Skip to content
Discussion options

You must be logged in to vote

I think you can currently achieve this without overriding any methods by setting expand=True but allow_expand=False?

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


class TreeApp(App):
    def compose(self) -> ComposeResult:
        tree = Tree("Root")
        tree.root.expand()

        node_one = tree.root.add("Node 1", expand=True, allow_expand=False)
        node_one.add_leaf("Node 1.1")
        node_one.add_leaf("Node 1.2")

        node_two = tree.root.add("Node 2", expand=True, allow_expand=False)
        node_two.add_leaf("Node 2.1")
        node_two.add_leaf("Node 2.2")

        yield tree


if __name__ == "__main__":
    app = TreeApp()
    app.run()

Replies: 1 comment 1 reply

Comment options

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

Answer selected by daddycocoaman
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