【问题标题】:Tkinter Treeview Append to List with get_children()Tkinter Treeview 使用 get_children() 附加到列表
【发布时间】:2018-01-23 06:40:14
【问题描述】:

我想将树视图的内容“保存”到可以再次显示的列表中。就像“设置”一样。

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)

我得到的输出是:

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

我想要的输出是[['abc', 123], ['hjk', 456]]

【问题讨论】:

  • 这个问题和tkinter没什么关系。这只是填充列表时的错误。

标签: python python-3.x list tkinter treeview


【解决方案1】:

简单地说:

machine_ports = []

以上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)

【讨论】:

    猜你喜欢
    • 2015-04-25
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 2018-03-19
    • 1970-01-01
    • 2012-04-23
    • 1970-01-01
    • 2022-11-23
    相关资源
    最近更新 更多