- Tkinter GUI Application Development Cookbook
- Alejandro Rodas de Paz
- 127字
- 2021-08-27 19:44:09
How to do it…
As we did in the preceding recipe, we will use five labels with different backgrounds to illustrate the distribution of the cells:
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 , 'sticky': 'nswe' }
label_a.grid(row=0, column=0, **opts)
label_b.grid(row=1, column=0, **opts)
label_c.grid(row=0, column=1, rowspan=2, **opts)
label_d.grid(row=0, column=2, rowspan=2, **opts)
label_e.grid(row=2, column=0, columnspan=3, **opts)
if __name__ == "__main__":
app = App()
app.mainloop()
We also passed a dictionary of options to add some internal padding and expand the widgets to all the available space in the cells.
推薦閱讀
- ASP.NET Web API:Build RESTful web applications and services on the .NET framework
- JavaScript高效圖形編程
- Learning Bayesian Models with R
- 實用防銹油配方與制備200例
- Django:Web Development with Python
- Learning SQLite for iOS
- Getting Started with SQL Server 2012 Cube Development
- 面向對象程序設計(Java版)
- ASP.NET 3.5程序設計與項目實踐
- Visual Basic程序設計上機實驗教程
- Mastering Unity 2D Game Development(Second Edition)
- Swift 4從零到精通iOS開發
- Visualforce Developer’s guide
- Visual Basic程序設計(第三版)
- Vue.js 3應用開發與核心源碼解析