使用treeview Python中的行制作带有for循环的嵌套列表

使用treeview Python中的行制作带有for循环的嵌套列表,python,Python,我想用从treeview获得的行中的值创建嵌套列表。 我想得到这样的东西: [[ , , ], [ , , ], [ , , ]...] 嵌套列表的数量应等于树视图中的行数,并且每个嵌套列表应有5项。 但我的程序一直将所有行中的所有值放在一个嵌套列表中,嵌套列表的数量等于行的数量。我怎样才能解决这个问题 ListOnePar=[] ListTwoPar=[] for child in tree1.get_children(id1): one=round(float(tree1.it

我想用从treeview获得的行中的值创建嵌套列表。 我想得到这样的东西:

[[ , , ], [ , , ], [ , , ]...]
嵌套列表的数量应等于树视图中的行数,并且每个嵌套列表应有5项。 但我的程序一直将所有行中的所有值放在一个嵌套列表中,嵌套列表的数量等于行的数量。我怎样才能解决这个问题

ListOnePar=[]
ListTwoPar=[]

for child in tree1.get_children(id1):

    one=round(float(tree1.item(child,"values")[1]),2)
    two=round(float(tree1.item(child,"values")[2]),2)
    tree=round(float(tree1.item(child,"values")[3]),2)
    four=round(float(tree1.item(child,"values")[5]),1)
    five=round(float(tree1.item(child,"values")[6]),1)

    ListTwoPar.append(one)
    ListTwoPar.append(two)
    ListTwoPar.append(tree)
    ListTwoPar.append(four)
    ListTwoPar.append(five)

    ListOnePar.append(ListTwoPar)

print(ListOnePar)

您需要将第二个列表创建粘贴到循环中;否则,它只会继续为每一行添加相同的列表

for child in tree1.get_children(id1):
    ListTwoPar=[]

你太棒了!谢谢