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

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.

主站蜘蛛池模板: 栖霞市| 东乌珠穆沁旗| 德保县| 沛县| 衡阳县| 清镇市| 旬邑县| 山丹县| 德格县| 徐闻县| 宜章县| 青田县| 通河县| 崇文区| 习水县| 凌源市| 札达县| 循化| 广德县| 抚宁县| 抚远县| 弥渡县| 东海县| 灵台县| 尚义县| 二连浩特市| 旬阳县| 南安市| 福贡县| 乌拉特中旗| 安塞县| 沁水县| 长岭县| 江陵县| 宜良县| 西吉县| 顺义区| 张家口市| 招远市| 洞头县| 沭阳县|