-
Notifications
You must be signed in to change notification settings - Fork 0
/
a_table_1.py
55 lines (41 loc) · 1.53 KB
/
a_table_1.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import tkinter as tk
from tkinter import ttk
headings = ["Heading0", "Heading1", "Heading2", "Heading3"]
root = tk.Tk()
root.title("Add headings")
frame1 = tk.Frame(root)
frame1.pack()
tree = ttk.Treeview(frame1)
tree["columns"] = ("C1", "C2")
tree.column("#0", width=500, minwidth=400, stretch=tk.NO)
tree.column("C1", width=200, minwidth=200, stretch=tk.NO)
tree.column("C2", width=200, minwidth=200, stretch=tk.NO)
tree.heading("#0", text="Name", anchor=tk.W)
tree.heading("C1", text="Type", anchor=tk.W)
tree.heading("C2", text="Index", anchor=tk.W)
t = {}
for i in range(5):
t[i] = tree.insert("", i, text="Example " + str(i), values=("val1", "val2"))
tree.pack(expand=True, fill="both")
def create():
for i, val in enumerate(headings):
if i == 0:
tree2.column("#0", width=200, minwidth=200, stretch=tk.NO)
elif i == 1:
tree2["columns"] = ("C1",)
tree2.column("C1", width=800, minwidth=200, stretch=tk.NO)
else:
tree2["columns"] = tree2["columns"] + ("C" + str(i),)
tree2.column("C" + str(i), width=800, minwidth=200, stretch=tk.NO)
for i, val in enumerate(headings):
if i == 0:
tree2.heading("#0", text=val, anchor=tk.W)
elif i == 1:
tree2.heading("C1", text=val, anchor=tk.W)
else:
tree2.heading("C" + str(i), text=val, anchor=tk.W)
btn1 = tk.Button(frame1, text="Add", command=create)
btn1.pack(side="top")
tree2 = ttk.Treeview(frame1)
tree2.pack(expand=True, fill="both")
root.mainloop()