如何在wxpython中获取CT.CustomTreeCtrl中的所有节点

How to get all the nodes from CT.CustomTreeCtrl in wxpython

我在 wxpython 中使用 CT.CustomTreeCtrl 创建了一棵树。现在我想阅读树中的所有 children。我的树结构就像 a->b->c,其中 a 是根节点,b 是 a 的 child 和 c 的 parent。

当我使用 'GetFirstChild(root)' 时,我得到了 child 节点 'b'。但是我想看c的文字。对此的任何线索都适用

我以前用过类似的方法。这将遍历父节点中的每个项目并递归地生成每个具有子节点的项目。

def get_all_nodes(self, parent_node):
    for child in parent_node.GetChildren():
        if self.ItemHasChildren(child):
            yield child
            for grandchild in self.get_all_nodes(child):
                yield grandchild

编辑: 要获取每个项目的文本,请使用方法 'GetItemText'

def get_all_nodes(self, parent_node):
    for child in parent_node.GetChildren():
        if self.ItemHasChildren(child):
            yield self.GetItemText(child)
            for grandchild in self.get_all_nodes(child):
                yield self.GetItemText(grandchild)