tkinter frame not expanding to fit window?
Peter Otten
__peter__ at web.de
Tue Apr 17 14:24:16 EDT 2018
Zobeid Zuma wrote:
> I've just started working through the tutorial here → http://
> www.tkdocs.com/tutorial/firstexample.html and I already hit some behavior
> that I don't understand. The frame doesn't expand when I resize the
> window! The tutorial says these lines should do it:
>
> mainframe.columnconfigure(0, weight=1)
> mainframe.rowconfigure(0, weight=1)
>
> As an experiment I tried commenting those lines out, just to see if
> anything would change, and nothing did. So it seems they aren't working
> for me, but I don't know why. Any suggestions?
>
> This is all running on Ubuntu MATE 17.10 and tk8.6.
Here is a minimalistic example with a red Frame in a blue window:
import tkinter as tk
root = tk.Tk()
root["background"] = "blue"
frame = tk.Frame(root, background="red")
frame.grid(row=0, column=0, sticky=tk.NSEW)
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
root.mainloop()
When you run it as is you should see the red frame.
When you remove the lines
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
you should see the blue window instead. When you put those lines back in,
but change the line
frame.grid(row=0, column=0, sticky=tk.NSEW)
to
frame.grid(row=0, column=0)
you will also see blue.
So my crystal ball says that in the code that you don't show you forgot to
make the Frame "sticky".
More information about the Python-list
mailing list