WxPython TreeCtrl without displaying the root while the arrow is displayed

I am creating a python tree visualizer using wxPython. It will be used as follows:

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 the root with the value "Tree." I made it so that it creates several roots, but then found out that I was not allowed to do this. I returned to the source code, but used it to change self.tree = wx.TreeCtrl(self):: self.tree = wx.TreeCtrl(self, style=wx.TR_HIDE_ROOT). It worked, but it did not show small arrows on the side, so you would not know which nodes had children. Is there a way to hide the root of the node, but keep the arrows. Note. I am on a Mac using Python version 2.5 and wxPython version 2.8.4.0.

+3
source share
2 answers

Note. When I posted this, I did not understand that you can apply several styles to trees.
After trying everything, I realized that this is a combination of TR_HIDE_ROOT and TR_HAS_BUTTONS, which does the trick, hiding the root, still showing arrows on the left side that allow you to collapse and hide nodes with children. This is the code where I ended up:

self.tree = wx.TreeCtrl(self, style=wx.TR_HAS_BUTTONS + wx.TR_HIDE_ROOT)
+8
source

It could wxTR_LINES_AT_ROOTbe what you are looking for?

From the wxWidgets documentation :

wxTR_LINES_AT_ROOT
  Use this style to show lines between root nodes.
  Only applicable if wxTR_HIDE_ROOT is set
  and wxTR_NO_LINES is not set.

disclaimer: this is for WX in C ++, not python, but it should be equivalent

+1
source

Source: https://habr.com/ru/post/1747456/


All Articles