【发布时间】:2014-08-29 00:01:58
【问题描述】:
我试图找到一个代码来知道树节点是否 在 Tkinter python 2.6 中有孩子。我尝试使用类似的 wxpython 代码,但失败了! 这是因为我想用我的 ttk treeview 小部件做一些编程,如果我能得到这些细节的话 就像是否存在任何子节点(真/假)或有多少子节点计数,那么这对我来说很容易 在我的程序中制作“IF-Conditions”。
有人请尽快帮助我
请注意我的代码
childItems= self.tree.ItemHasChildren("Arithmetic")
print childItems
错误:
AttributeError: Treeview 实例没有属性 'ItemHasChildren'
【问题讨论】:
-
你不能假设 Tkinter 中的方法与 wxpython 中的对应方法同名。看看the documentation。我不知道该模块,但我认为
get_children是您正在寻找的。span> -
亲爱的托比亚斯,没关系! get_children,我尝试了很多次,但是对它的方法参数(item = None)感到困惑,如何在get children方法中编写和指定这个参数,这个方法的一些例子很好理解,到目前为止我找不到,请您帮帮我。
-
正如我所说,我自己对该模块没有太多经验。我假设您在树的根元素上调用该方法,并将您想要其子节点的节点作为参数传递。你试过这个吗?
-
正如tobias_k所说:你试过
print self.tree.get_children("Arithmetic")吗? -
亲爱的@furas 和@Tobias,非常感谢您的回复! print self.tree.get_children("Arithmetic") OR NodesData = self.tree.get_children("Arithmetic") 是的,我尝试了同样的方法,但我遇到了以下错误!!!请注意错误:第 60 行,在 ResetTreedata print self.tree.get_children("Arithmetic") File "C:\Python26\lib\site-packages\ttk.py",第 1231 行,在 get_children return self.tk.call (self._w, "children", item or '') or () TclError: Item Arithmetic not found
标签: tkinter python-2.6