展开/折叠 ttk Treeview 分支 [英] Expand/collapse ttk Treeview branch

查看:58
本文介绍了展开/折叠 ttk Treeview 分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在 ttk.Treeview 中折叠和展开分支的命令.

I would like to know the command for collapsing and expanding a branch in 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.

推荐答案

对我来说(Win 7,Py2.7),你的例子在分支关闭时出现,但你可以用这个命令随意打开或关闭它:

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:

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

将其设置为 False 以关闭它.

Set it to False to close it.

查看这些主题:

25.2.tkinter.ttk - Tk 主题小部件 - 项目选项

25.2.tkinter.ttk - Tk 主题小部件 - 项目方法

可以使用 insert() 或事后使用 item() 设置项目选项.

Item options can be set either with insert(), or after the fact with item().

这篇关于展开/折叠 ttk Treeview 分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆