-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSimpleTreeview.py
34 lines (24 loc) · 1006 Bytes
/
SimpleTreeview.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
### File Name: Tkinter ttk Treeview Simple Demo
### Reference: http://knowpapa.com/ttk-treeview/
from tkinter import *
from tkinter import ttk
root = Tk()
tree = ttk.Treeview(root)
tree["columns"] = ("one", "two")
tree.column("one", width=150)
tree.column("two", width=100)
tree.heading("one", text="column A")
tree.heading("two", text="column B")
### insert format -> insert(parent, index, iid=None, **kw)
### reference: https://docs.python.org/3/library/tkinter.ttk.html#tkinter.ttk.Treeview
tree.insert("", 0, text="Line 1", values=("1A", "1b"))
tree.insert("", "end", text="sub dir 2", values=("2A", "2B"))
### insert sub-item, method 1
id2 = tree.insert("", "end", "dir2", text="Dir 2")
tree.insert(id2, "end", text="sub dir 2-1", values=("2A", "2B"))
tree.insert(id2, "end", text="sub dir 2-2", values=("2A-2", "2B-2"))
### insert sub-item, method 2
tree.insert("", "end", "dir3", text="Dir 3")
tree.insert("dir3", "end", text=" sub dir 3", values=("3A", "3B"))
tree.pack()
root.mainloop()