wxPython TreeCtrl 不显示根但仍显示箭头

发布于 2024-09-03 10:12:22 字数 474 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

杯别 2024-09-10 10:12:22

注意:当我发布此内容时,我没有意识到您能够对树应用多种样式。
在尝试了一切之后,我意识到它是 TR_HIDE_ROOT 和 TR_HAS_BUTTONS 的组合,它可以隐藏根,同时仍然在左侧显示箭头,允许您折叠和隐藏带有子节点的节点。这是我最终使用的代码:

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

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)
那支青花 2024-09-10 10:12:22

wxTR_LINES_AT_ROOT 可能是您要找的东西吗?

来自 wxWidgets 文档

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.

免责声明:这是针对 WX 的c++,不是 python,但它应该是等效的

Could wxTR_LINES_AT_ROOT be what you're looking for?

From 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文