我正在尝试覆盖treeview表中父级中的子级。 我尝试过的一种方法是删除并插入新的子行,但在运行代码后,我发现错误:
_tkinter.TclError: Item I003 I004 I005 I006 not found
在我出现这个错误之前,删除和插入新的子项大约工作了5次。从我可以看出,一旦所有的孩子都被添加和删除,一旦我得到上面的错误。就像iid一旦被删除就不会被重置一样
我需要选择一个特定的子项并覆盖它,或者删除一个子项并在其位置插入一个新的子项
这是我的一些代码,我在其中获取所选选项卡中的子项,删除它们并插入新的子项
tree_select = tree.focus()
clear_tree_children = tree.get_children(tree_select)
clear_tree_children = tree.get_children(tree_select)
if len(clear_tree_children) > 0:
for child in clear_tree_children:
tree.delete(clear_tree_children)
print(child)
if tree_phys.get() == 1:
disPhys = ("", "", "", "", "", "Physical Disability")
tree.insert(parent=tree_select, index=END, values=disPhys)
有人对我如何解决这个问题有什么想法或其他方法吗
谢谢,雅各布
是的,确切地说,tkinter以增量方式生成默认iid,而不关心之前的某些项目是否已被删除。如果您需要删除/插入项目,并且仍然能够使用相同的iid访问它们,则在创建项目时应为自己分配iid:
如果您只想更改给定单元格中的值,JacksonPro的答案非常有效。但是,如果要同时更改整行,可以使用
下面是一个示例,当双击整行时,整行都会发生更改:
如果要覆盖选定行,可以使用
.set(iid, column, value)
下面是我不久前编写的示例代码(双击任意一行):
相关问题 更多 >
编程相关推荐