[Tutor] Expanding a frame into an expanding window

Phil phillor9 at gmail.com
Mon Mar 25 18:57:09 EDT 2024


On 25/3/24 21:05, Alan Gauld via Tutor wrote:
> On 25/03/2024 07:07, Phil wrote:
>
> I'm not seeing the problem. Both widgets move when the window is expanded.
> Here is my code, only slightly modified from yours:
>
>
> Thank you Alan for your reply and I appreaciate it geatly. The problem only occures when the class SimpleEntry is imported. The ButtonFrame widget moves but the EnrtyFrame widget (SimpleEntry) does not move.

import tkinter as tk
from tkinter_entry_class import SimpleEntry


class EntryFrame(tk.Frame):
     def __init__(self, parent):
         super().__init__(parent)
         self.entry_widget = SimpleEntry(self, bg_colour="yellow")
         self.entry_widget.pack(fill="both", expand=True)


class ButtonFrame(tk.Frame):
     def __init__(self, parent):
         super().__init__(parent, bg="light green")
         self.add_button = tk.Button(self, text="Press me", 
command=self.on_button_click)
         self.add_button.pack()

     def on_button_click(self):
         pass


class App(tk.Tk):
     def __init__(self):
         super().__init__()
         self.title("Simple Class Test")

         self.entry_frame = EntryFrame(self)
         self.button_frame = ButtonFrame(self)

         self.entry_frame.grid(row=0, column=0, padx=5, pady=5, 
sticky="nsew")
         self.button_frame.grid(row=1, column=0, padx=5, pady=5, 
sticky="nsew")

         self.grid_rowconfigure(0, weight=1)
         self.grid_rowconfigure(1, weight=1)
         self.grid_columnconfigure(0, weight=1)


def main():
     app = App()
     app.mainloop()


if __name__ == "__main__":
     main()


-- 
Regards,
Phil


More information about the Tutor mailing list