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

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:

主站蜘蛛池模板: 沈丘县| 灵宝市| 磐石市| 邛崃市| 河北区| 阿拉善右旗| 洛浦县| 图木舒克市| 宣化县| 洪洞县| 锡林浩特市| 静安区| 吕梁市| 吉木萨尔县| 西充县| 柘荣县| 汾西县| 青龙| 措美县| 大足县| 长葛市| 湖口县| 五大连池市| 泾源县| 漯河市| 新竹市| 台前县| 砚山县| 富平县| 绩溪县| 当涂县| 建水县| 通化市| 德兴市| 九龙县| 深州市| 珠海市| 白水县| 美姑县| 沙河市| 富锦市|