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:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset