Reputation: 33
I am using Python3 TTK Treeview to display a tree. But first, sub nodes are not indented and only first sublevel of the tree is visible. A parent sub node doesn't display its children.
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()
Result :
First display
First parent node expanded: Its first child (Trois) which is a parent node doesn't display the expansion possibility glyph, and children are not indented.
Upvotes: 1
Views: 2442
Reputation: 8234
Welcome. Please take time to append your question(s) into the main Question section. This will help other future users to learn from your question and meet stackoverflow's standards.
To allow you to see the directory, i.e. tree structure, you need to:
You can also added the "open = True" in the .insert method for 'Un' to show the children of 'Un' at the onset.
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()
Upvotes: 6