Skip to content
Discussion options

You must be logged in to vote

Yes, labels of nodes in Tree can be Rich renderables (as long as they're no more than one line in length). Here's a silly example of setting up some leaf nodes that can be toggled when the user selects them:

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

class ToggleTree( Tree[ bool ] ):

    def on_tree_node_selected( self, event: Tree.NodeSelected ) -> None:
        if not event.node.children:
            event.node.data = not event.node.data
            if event.node.data:
                event.node.label = ":thumbsup:"
            else:
                event.node.label = ":thumbsdown:"
            event.node.tree.refresh()

class Check…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@sergi0g
Comment options

@davep
Comment options

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