In Python 3.7, I need to expand all child nodes when a node is opened. Lets use the following example:
A
--A.1
----A.1.1
--A.2
----A.2.1
----A.2.2
B
--B.1
----B.1.1
--B.2
With this example, when A is expanding in the GUI, all child nodes of A should also be expanded.
As per the official treeview documentation, you can bind the event "<>", which is generated immediately before the selected node is expanded. Knowing this, I can bind the event as such:
tree.bind('<<TreeviewOpen>>', handleOpenEvent)
Now I can write a method to handle the event, using the strategy from this solution like so:
def handleOpenEvent(event):
tree.item(tree.focus(), open=True) # Tried with and without
for child in tree.get_children(tree.focus()):
tree.item(child, open=True)
Whatever I try, this code will NOT expand ALL children on the selected node. I've tried making it so expanding A will expand all B nodes, and that DOES work, but I'm not able to expand all A nodes when A is expanded. It seems like there's some extra underlying things that Treeview is doing that I don't know about. Any thoughts?