Re: Expanding a frame into an expanding window

Alan Gauld via Tutor <[email protected]> Mon, 25 Mar 2024 11:05:34 +0000
Newsgroups gmane.comp.python.tutor
Message-ID <[email protected]>
On 25/03/2024 07:07, Phil wrote:

> When the app window is expanded the frames expand and frame's widgets 
> move except for the frame that uses the imported class. That frame 
> expands but the widgets on that frame remain in place. So there must be 
> a problem with the custom widget class.

I'm not seeing the problem. Both widgets move when the window is expanded.
Here is my code, only slightly modified from yours:


########################
import tkinter as tk


class SimpleEntryGrid(tk.Frame):
     def __init__(self, parent, bg_colour="light blue"):
         super().__init__(parent, bg=bg_colour)

         self.enter_label = tk.Label(self, text="enter a number")
         self.number_enter = tk.Entry(self)

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


class SimpleEntryPack(tk.Frame):
     def __init__(self, parent, bg_colour="light blue"):
         super().__init__(parent, bg=bg_colour)

         self.enter_label = tk.Label(self, text="enter a number")
         self.number_enter = tk.Entry(self)

         self.enter_label.pack(side=tk.LEFT,
                               padx=5, pady=5, expand=True)
         self.number_enter.pack(side=tk.LEFT,
                                padx=5, pady=5, expand=True)

top = tk.Tk()
seg = SimpleEntryGrid(top)
sep = SimpleEntryPack(top, bg_colour="grey")
seg.pack(side=tk.LEFT, padx=15, pady=10, expand=True)
sep.pack(side=tk.LEFT, padx=15, pady=10, expand=True)

top.mainloop()


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor