- Tkinter GUI Application Development Cookbook
- Alejandro Rodas de Paz
- 108字
- 2021-08-27 19:44:08
How to do it…
We will use five Label widgets with different texts and background colors to help us identify each rectangular region:
import tkinter as tk
class App(tk.Tk):
def __init__(self):
super().__init__()
label_a = tk.Label(self, text="Label A", bg="yellow")
label_b = tk.Label(self, text="Label B", bg="orange")
label_c = tk.Label(self, text="Label C", bg="red")
label_d = tk.Label(self, text="Label D", bg="green")
label_e = tk.Label(self, text="Label E", bg="blue")
opts = { 'ipadx': 10, 'ipady': 10, 'fill': tk.BOTH }
label_a.pack(side=tk.TOP, **opts)
label_b.pack(side=tk.TOP, **opts)
label_c.pack(side=tk.LEFT, **opts)
label_d.pack(side=tk.LEFT, **opts)
label_e.pack(side=tk.LEFT, **opts)
if __name__ == "__main__":
app = App()
app.mainloop()
We also added some options with the opts dictionary to make the size of each region clear:

推薦閱讀
- 基于粒計算模型的圖像處理
- Java Web開發學習手冊
- Manga Studio Ex 5 Cookbook
- 機械工程師Python編程:入門、實戰與進階
- Hands-On GPU:Accelerated Computer Vision with OpenCV and CUDA
- C#實踐教程(第2版)
- 軟件測試教程
- Microsoft 365 Certified Fundamentals MS-900 Exam Guide
- PHP編程基礎與實踐教程
- 零基礎學Scratch 3.0編程
- 貫通Tomcat開發
- Hacking Android
- Python Linux系統管理與自動化運維
- Puppet 5 Beginner's Guide(Third Edition)
- 面向對象分析與設計(第3版)