简体   繁体   English

Tkinter Treeview使用get_children()追加到列表

[英]Tkinter Treeview Append to List with get_children()

I want to 'save' the contents of the treeview into a list which I can display again. 我想将树状视图的内容“保存”到一个列表中,然后可以再次显示。 Just like 'settings'. 就像“设置”一样。

设置示例

for child in self.terminal_tree.get_children():
    print(self.terminal_tree.item(child)["values"])

    machine_ports = []
    machine_ports.append(self.terminal_tree.item(child)["values"])
    print(machine_ports)

The output I get is: 我得到的输出是:

['abc', 123]
[['abc', 123]]
['hjk', 456]
[['hjk', 456]]

The output that I want is [['abc', 123], ['hjk', 456]] 我想要的输出是[['abc', 123], ['hjk', 456]]

Simply put: 简单的说:

machine_ports = []

above for loop: 上面的 for循环:

machine_ports = []
for child in self.terminal_tree.get_children():
    print(self.terminal_tree.item(child)["values"])
    machine_ports.append(self.terminal_tree.item(child)["values"])
    print(machine_ports)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM