Prevent Tree Node from collapsing #4407
-
I have a I'm pretty sure I can handle this by subclassing Tree and overriding Here is the code I'm currently using: class NoncollapsibleTree(Tree):
def _toggle_node(self, node: TreeNode) -> None:
if not node.allow_expand:
return
if not node.is_expanded:
node.expand() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I think you can currently achieve this without overriding any methods by setting 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() |
Beta Was this translation helpful? Give feedback.
I think you can currently achieve this without overriding any methods by setting
expand=True
butallow_expand=False
?