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-zeroweightarguments. Otherwise, nothing would show up. - It's thus possible to have the main
Frameusingpack(), but its immediate childFramesall usinggrid(); Inside each of these childFrameson 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
Framewith a childFramefull of widgets laid out horizontally, e.g., all widgets usegrid(sticky='nsew'), and the childFrameusespack(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.