[英]Python Tkinter Treeview search all entries
我用树形视图来显示文件夹中包含的所有项目。
我创建这个函数的所有条目:
def SUBS(path, parent):
for p in os.listdir(path):
abspath = os.path.join(path, p)
parent_element = tree.insert(parent, 'end', text=p, open=True)
if os.path.isdir(abspath):
SUBS(abspath, parent_element)
现在我想用这个功能搜索它:
def search(event, item=''):
children = tree.get_children(item)
for child in children:
text = tree.item(child, 'text')
if text.startswith(entry.get()):
tree.selection_set(child)
问题是,搜索功能只能通过第一个“节点”进行搜索。 不是全部。 那么,如何寻找通过量孩子的孩子吗? 它们是怎样被称为?
为什么不在SUBS函数中使用递归?
def search(event, item=''):
children = tree.get_children(item)
for child in children:
text = tree.item(child, 'text')
if text.startswith(entry.get()):
tree.selection_set(child)
search(None, item=child) # Use the function for all the children, their children, and so on..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.