我正在使用Python3 TTK Treeview来显示树。但首先,子节点没有缩进,只有树的第一个子级可见。父子节点不显示其子节点。
from tkinter import *
from tkinter.ttk import *
Win = Tk()
entries_tree = Treeview(Win, columns = ("Glyph", "Name"), show="tree")
entries_tree.column("#0", width = 20)
entries_tree.column("#1", width = 20)
entries_tree.pack()
#Test
Un = entries_tree.insert("", "end", values = ["X", "Un"])
Deux = entries_tree.insert("", "end", values = ["X", "Deux"])
Trois = entries_tree.insert(Un, "end", values = ["X", "Un Un"], open = True)
Quatre = entries_tree.insert(Un, "end", values = ["X", "Un Deux"])
Cinq = entries_tree.insert(Un, "end", values = ["X", "Un Trois"])
Six = entries_tree.insert(Trois, "end", values = ["X", "Un Un Un"])
Sept = entries_tree.insert(Trois, "end", values = ["X", "Un Un Deux"])
Win.mainloop()
结果:
第一次显示
扩展的第一个父节点:作为父节点的第一个子节点(Trois)不显示扩展可能性字形,并且子节点不缩进。
答案 0 :(得分:4)
欢迎。请花时间将您的问题附加到主要问题部分。这将有助于其他未来用户从您的问题中学习并满足stackoverflow的标准。
要允许您查看目录,即树结构,您需要:
您还可以添加" open = True"在' Un'的.insert方法中。向孩子们展示Un'在开始时。
from tkinter import *
from tkinter.ttk import *
Win = Tk()
entries_tree = Treeview(Win, columns = ("Glyph", "Name"), show="tree")
entries_tree.column("#0", width = 120, stretch=0)
entries_tree.column("#1", width = 20, stretch=0)
entries_tree.pack()
#Test
Un = entries_tree.insert("", "end", text='Un', values = ["X", "Un"], open = True)
Deux = entries_tree.insert("", "end", text='Deux', values = ["X", "Deux"])
Trois = entries_tree.insert(Un, "end", text='Trois', values = ["X", "Un Un"], open = True)
Quatre = entries_tree.insert(Un, "end", text='Quatre', values = ["X", "Un Deux"])
Cinq = entries_tree.insert(Un, "end", text='Cinq', values = ["X", "Un Trois"])
Six = entries_tree.insert(Trois, "end", text='Six', values = ["X", "Un Un Un"])
Sept = entries_tree.insert(Trois, "end", text='Sept', values = ["X", "Un Un Deux"])
Win.mainloop()