This is what I am trying to achieve
Here is the code:
class GeometryFrame(tk.Frame):
def __init__(self, parent):
super().__init__(parent)
self.columnconfigure(0, weight=1)
rectangle_1 = tk.Label(self, text="Rectangle 1", bg="green", fg="white")
rectangle_1.grid(column=0, row=0, ipadx=10, ipady=10, sticky="EW")
rectangle_2 = tk.Label(self, text="Rectangle 2", bg="red", fg="white")
rectangle_2.grid(column=0, row=1, ipadx=10, ipady=10, sticky="EW")
class App(tk.Tk):
def __init__(self):
super().__init__()
self.geometry("600x100")
self.columnconfigure(0, weight=1)
self.geo_frame = GeometryFrame(self)
self.geo_frame.grid(column=0, row=0)
if __name__ == "__main__":
app = App()
app.mainloop()
How to fix this? (NOTE: I want to use grid and not pack).
I get the desired result if I remove the GeometryFrame class and place it's code to the App class.
class App(tk.Tk):
def __init__(self):
super().__init__()
self.geometry("600x100")
self.columnconfigure(0, weight=1)
# self.rowconfigure(0, weight=1)
rectangle_1 = tk.Label(self, text="Rectangle 1", bg="green", fg="white")
rectangle_1.grid(column=0, row=0, ipadx=10, ipady=10, sticky="EW")
rectangle_2 = tk.Label(self, text="Rectangle 2", bg="red", fg="white")
rectangle_2.grid(column=0, row=1, ipadx=10, ipady=10, sticky="EW")


