Skip to content Skip to sidebar Skip to footer

Python: Getting Started With Tk, Widget Not Resizing On Grid?

I'm just getting started with Python's Tkinter/ttk and I'm having issues getting my widgets to resize when I use a grid layout. Here's a subset of my code which exhibits the same i

Solution 1:

Try specifying the sticky argument when you do self.grid. Without it, the Frame won't resize when the window does. You'll also need to rowconfigure master and self, just as you have columnconfigured them.

#rest of code goes here...
    xsb.grid(row=1, column=0, sticky='sew')
    self.grid(sticky="nesw")
    master.columnconfigure(0, weight=1)
    master.rowconfigure(0,weight=1)
    self.columnconfigure(0, weight=1)
    self.rowconfigure(0, weight=1)

Alternatively, instead of gridding the Frame, pack it and specify that it fills the space it occupies. Since the Frame is the only widget in the Tk, it doesn't really matter whether you pack or grid.

#rest of code goes here...
    xsb.grid(row=1, column=0, sticky='sew')
    self.pack(fill=tk.BOTH, expand=1)
    self.columnconfigure(0, weight=1)
    self.rowconfigure(0, weight=1)

Post a Comment for "Python: Getting Started With Tk, Widget Not Resizing On Grid?"