- Tkinter GUI Application Development Cookbook
- Alejandro Rodas de Paz
- 137字
- 2021-08-27 19:44:10
How to do it…
The labels that we will display have different backgrounds and are defined in the order they are placed from left to right and top to bottom:
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")
label_a.place(relwidth=0.25, relheight=0.25)
label_b.place(x=100, anchor=tk.N,
width=100, height=50)
label_c.place(relx=0.5, rely=0.5, anchor=tk.CENTER,
relwidth=0.5, relheight=0.5)
label_d.place(in_=label_c, anchor=tk.N + tk.W,
x=2, y=2, relx=0.5, rely=0.5,
relwidth=0.5, relheight=0.5)
label_e.place(x=200, y=200, anchor=tk.S + tk.E,
relwidth=0.25, relheight=0.25)
if __name__ == "__main__":
app = App()
app.mainloop()
If you run the preceding program, you can see the overlapping between label_c and label_d in the center of the screen, something that we have not achieved with other geometry managers.
推薦閱讀
- Building a Recommendation Engine with Scala
- C++新經典
- Java程序設計案例教程
- Microsoft 365 Certified Fundamentals MS-900 Exam Guide
- Unity Android Game Development by Example Beginner's Guide
- Hacking Android
- 大數據時代的企業升級之道(全3冊)
- Implementing Microsoft Dynamics NAV(Third Edition)
- 3D Printing Designs:Octopus Pencil Holder
- Clojure for Finance
- HikariCP數據庫連接池實戰
- C/C++程序設計教程
- Python Django Web從入門到項目實戰(視頻版)
- Mastering Linux Kernel Development
- jQuery權威指南