I want to eliminate strange extra space that seems to resist any size tweaking in my layout when using grid()
alone, but calling in pack()
sometimes make things worse: The GUI simply disappear entirely!
I read a few eye-opening layout answers from @Bryan Oakley such as:
When to use pack or grid layouts in tkinter?
and
Tkinter: grid or pack inside a grid?
but when I get down to write my own stuff, I still often have troubles.
My understanding:
- I must have a Frame to fill the
root window
, otherwise there'd be no hope to fill the extra space in the window, however I tweak widgets alone. - For all the child widgets sitting inside a common parent
Frame
, I must use eitherpack()
orgrid()
but not both. - When using
grid()
in a Frame, it's mandatory to specifyFrame.grid_rowconfigure()
and.grid_columnconfigure()
with non-zeroweight
arguments. Otherwise, nothing would show up. - It's thus possible to have the main
Frame
usingpack()
, but its immediate childFrames
all usinggrid()
; Inside each of these childFrames
on the grid, we could thenpack()
their own child widgets. In other words, we could interleavegrid()
andpack()
by "regions" or container hierarchy levels, but never mix them in the same container: The only restriction. - By a careful weight design, I could fill a horizontal space in a parent
Frame
with a childFrame
full of widgets laid out horizontally, e.g., all widgets usegrid(sticky='nsew')
, and the childFrame
usespack(side='top', fill='both', expand=True)
.
If my understanding was correct, then I could never figure out why #5 couldn't work for me, e.g., there is always unused extra space towards the right end of my horizontal child Frame
inside the main Frame
of the root window.
UPDATE 2
I figured it out. #5 didn't work for me because I forgot to specify .grid_columnconfigure(0, weight=1)
in the main Frame
before using grid()
. My bad! Case closed.
UPDATE
I'm on macOS High Sierra, running python 3.6.4 Homebrew.