Skip to content

Commit

Permalink
Add post
Browse files Browse the repository at this point in the history
  • Loading branch information
mike_chen committed Jun 5, 2021
1 parent 1ef716d commit 5299cea
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion _posts/2020-08-29-python-tkinter.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,35 @@ cb.pack()
## TreeView
可捲動的表格
```python
def sort_column(col, reverse):
"""依此欄位排序"""
items = [(tv.set(child, col), child) for child in tv.get_children()] #取出欄位值對應項目
items.sort(reverse=reverse)

for index, (val, child) in enumerate(items):
tv.move(child, '', index) # 依新的索引移動項目

tv.heading(col, command=lambda: sort_column(col, not reverse)) # 重新定義方法為反向排序

vbar = Scrollbar(window)
vbar.pack(side=RIGHT, fill=Y)

Style().configure('user.Treeview', rowheight=110) # 自訂風格,調整欄高為110
tv = Treeview(window, yscrollcommand=vbar.set, show='headings', style='user.Treeview')
tv.pack(side=LEFT, fill=BOTH, expand=True)
tv['columns'] = 'id', 'name', 'password', 'auth_code'
tv.heading('#1', text='id')
tv.heading('#1', text='id', command=lambda: sort_column('#1', False))
tv.heading('#2', text='name')
tv.heading('#3', text='password')
tv.heading('#4', text='auth_code')
vbar.config(command=tv.yview)
```

## Widget
winfo_exists() 可檢查是否存在/顯示

winfo_children() 回傳底下所有widget

## Grid
自動佈局,每三個項目為一列
```python
Expand Down

0 comments on commit 5299cea

Please sign in to comment.