I am making a python tree visualizer using wxPython. It would be used like so:
show_tree([ 'A node with no children', ('A node with children', 'A child node', ('A child node with children', 'Another child')) ])
It worked fine but it shows a root with a value of "Tree". I made it so that it would create multiple roots but then learned that I wasn't allowed to do that. I reverted to the original code but used changed it from this: self.tree = wx.TreeCtrl(self)
to this: self.tree = wx.TreeCtrl(self, style=wx.TR_HIDE_ROOT)
. It worked but it didn't show the little arrows on the side so you wouldn't know which nodes had children. Is there any way to hide the root node but keep the arrows. Note: I am on a Mac using Python version 2.5 and wxPython version 2.8.4.0.
Note: When I posted this I did not realize you were able to apply multiple styles to trees.
After trying everything, I realized that it was a combination of TR_HIDE_ROOT and TR_HAS_BUTTONS that does the trick of hiding the root while still showing arrows on the left side that allow you to collapse and hide nodes with children. This is the code I ended up using:
self.tree = wx.TreeCtrl(self, style=wx.TR_HAS_BUTTONS + wx.TR_HIDE_ROOT)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With