简体   繁体   English

展开/折叠ttk Treeview分支

[英]Expand/collapse ttk Treeview branch

I would like to know the command for collapsing and expanding a branch in ttk.Treeview. 我想知道在ttk.Treeview中折叠和扩展分支的命令。

Here is a minimalistic example code: 这是一个简约的示例代码:

#! coding=utf-8
import tkinter as tk
from tkinter import ttk

root = tk.Tk()
tree = ttk.Treeview(root)
tree.pack(fill=tk.BOTH,expand=True)

tree.insert("", index="end",iid="Main", text="main branch")
tree.insert("Main", index="end", text="Stuff 1")
tree.insert("Main", index="end", text="Stuff 2")

root.mainloop()

What command opens and/or expands the "main branch"? 什么命令打开和/或扩展“主分支”? There has to be one, since these are called when clicking the plus and minus signs. 必须有一个,因为在点击加号和减号时会调用它们。

For me (Win 7, Py2.7), your example comes up with the branch closed, but you can open or close it as you like with this command: 对我来说(Win 7,Py2.7),您的示例会关闭分支,但您可以使用此命令打开或关闭它:

tree.item("Main", open=False)

Set it to False to close it. 将其设置为False以关闭它。

See these topics: 请参阅以下主题:

25.2. 25.2。 tkinter.ttk - Tk themed widgets - Item options tkinter.ttk - Tk主题小部件 - 项目选项

25.2. 25.2。 tkinter.ttk - Tk themed widgets - item method tkinter.ttk - Tk主题小部件 - 项目方法

Item options can be set either with insert() , or after the fact with item() . 可以使用insert()设置项目选项,也可以使用item()设置项目选项。

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

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