如何从TreeView中收集单独列表中的数据?

2024-09-30 10:29:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python新手,我一直在解决这个问题。我使用一个代码,由“数据形状”创建,它从GUI中指向的TreeView中收集选定的标记

if f.GetType() == TreeView:
    ls = []
    nds = f.Nodes[0]
    iterateThroughNodes(nds,ls)

它使用递归函数“IterateThrowNodes()”返回一个列表“ls”中的所有标记

def iterateThroughNodes(collection,li):
        if hasattr(collection,'Nodes'):
            ntest = collection.Nodes
            if len(ntest) > 0:
                for i in ntest:
                    iterateThroughNodes(i,li)
            else:
                if collection.Checked:
                    li.append(collection.Tag)
return li

但如何在列表列表中保存值,在列表中,数据将根据它们在树中的位置进行分组

现在我有这个:

ls = [23,45,'reinforcement type', 'length']

我需要:

ls = [[23,45],['reinforcement type', 'length']]

你能为代码更改提供建议吗


Tags: 数据代码标记列表iftypelils

热门问题