[Tutor] Expanding a frame into an expanding window
Alan Gauld
alan.gauld at yahoo.co.uk
Mon Mar 25 07:05:34 EDT 2024
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
More information about the Tutor
mailing list