# -*- coding: utf-8 -*- import tkinter as tk import tkinter.ttk as ttk root = tk.Tk() root.title("tk33.py") root.geometry("400x325") ##################################### ttk.Style().configure('Treeview', background = 'lightgreen', foreground = 'black') tv = ttk.Treeview(root,show = 'tree', padding = 20) tv["columns"] = ('item','demand') tv.column('item', width = 50) tv.column('demand', width = 50) tv.heading('item', text = '品項') tv.heading('demand', text = '需求') tv.insert("", 0, 'classA', text = 'A班', values = ('電腦','1'), tag = 'A') cb = tv.insert('', 'end', 'classB', text = 'B班', tag = 'B') cb1 = tv.insert(cb, 'end', 'bitem1',text ='第一組', tag = 'B1') tv.insert(cb1, 'end', text = '大雄', value = ('筆芯',5), tag = 'B11') tv.insert(cb1, 'end', text = '靜香', value = ('紙張',9), tag = 'B12') cb2 = tv.insert(cb, 'end', 'bitem2',text = '第二組', values = ('原子筆', '20'), tag = 'B2') tv.insert('', 'end', 'classC', text = 'C班', tag = 'C') tv.insert('classC', 0, text = '第一組', values = ('鉛筆','10'), tag = 'C1') tv.pack() tv.tag_configure('A', background = 'pink', foreground = 'blue', font = "標楷體 14 bold") def show(event): lb.config(text = "A is selected.") tv.tag_bind('A', "<1>", show) lb = tk.Label(root, text = 'label') lb.pack() ##################################### root.mainloop()