官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 青神县| 论坛| 乌鲁木齐市| 平泉县| 郯城县| 苗栗市| 前郭尔| 温州市| 桃江县| 河池市| 望谟县| 孝感市| 兰州市| 石河子市| 满城县| 会东县| 微博| 大理市| 长寿区| 岳阳市| 碌曲县| 禹城市| 沈丘县| 镶黄旗| 巧家县| 邮箱| 即墨市| 泰宁县| 隆化县| 黎川县| 沙洋县| 南宁市| 大同县| 张家港市| 永善县| 曲麻莱县| SHOW| 星座| 阿巴嘎旗| 铜山县| 宁波市|