Do you want to let the user resize your entire application window, and distribute the extra space among its internal widgets? This requires some operations that are not obvious.
It's necessary to use the techniques for row and column
size management, described in Section 3.3, “Configuring column and row sizes”, to make your Application
widget's grid stretchable.
However, that alone is not sufficient.
Consider the trivial application discussed in Section 2, “A minimal application”, which contains only a button. If you run this application, and resize the window, the button stays the same size, centered within the window.
Here is a replacement version of the .__createWidgets()
method in the minimal application. In
this version, the button
always fills all the available space.
def createWidgets(self): top=self.winfo_toplevel() top.rowconfigure(0, weight=1) top.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) self.columnconfigure(0, weight=1) self.quit = Button ( self, text="Quit", command=self.quit ) self.quit.grid(row=0, column=0, sticky=N+S+E+W)
The “top level window” is the outermost
window on the screen. However, this window is not
your | |
This line makes row 0 of the top level window's grid stretchable. | |
This line makes column 0 of the top level window's grid stretchable. | |
Makes row 0 of the | |
Makes column 0 of the | |
The argument |
There is one more change that must be made. In the constructor, change the second line as shown:
def __init__(self, master=None): Frame.__init__(self, master) self.grid(sticky=N+S+E+W) self.createWidgets()
The argument sticky=N+S+E+W
to
self.grid()
is necessary so that
the Application
widget will
expand to fill its cell of the top-level window's grid.