wxPython TreeCtrl 不显示根但仍显示箭头
我正在使用 wxPython 制作一个 python 树可视化工具。它将像这样使用:
show_tree([ 'A node with no children', ('A node with children', 'A child node', ('A child node with children', 'Another child')) ])
它工作得很好,但它显示了一个值为“Tree”的根。我这样做是为了让它创建多个根,但后来发现我不被允许这样做。我恢复到原始代码,但使用将其从: self.tree = wx.TreeCtrl(self) 更改为: self.tree = wx.TreeCtrl(self, style=wx. TR_HIDE_ROOT)。它有效,但它没有显示侧面的小箭头,因此您不知道哪些节点有子节点。有没有办法隐藏根节点但保留箭头。注意:我在 Mac 上使用 Python 版本 2.5 和 wxPython 版本 2.8.4.0。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
注意:当我发布此内容时,我没有意识到您能够对树应用多种样式。
在尝试了一切之后,我意识到它是 TR_HIDE_ROOT 和 TR_HAS_BUTTONS 的组合,它可以隐藏根,同时仍然在左侧显示箭头,允许您折叠和隐藏带有子节点的节点。这是我最终使用的代码:
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:
wxTR_LINES_AT_ROOT
可能是您要找的东西吗?来自 wxWidgets 文档:
免责声明:这是针对 WX 的c++,不是 python,但它应该是等效的
Could
wxTR_LINES_AT_ROOT
be what you're looking for?From wxWidgets documentation:
disclaimer: this is for WX in c++, not python but it should be equivalent