如何通过树中的名称获取树cntrl项目?

时间:2019-01-29 09:03:54

标签: python-2.7

如何在树中按名称获取树cntrl项目?

这是我尝试过的:

def get_item_by_label(tree, search_text, root_item):
    #searching the item by name and returns it
    item, cookie = tree.GetFirstChild(root_item)

    while item.IsOk():
        text = tree.GetItemText(item)
        if text.lower() == search_text.lower():
            return item
        if tree.ItemHasChildren(item):
            match = get_item_by_label(tree, search_text, item)
            if match.IsOk():
                return match
        item, cookie = tree.GetNextChild(root_item, cookie)

    return root_item

0 个答案:

没有答案