import tkinter as tk
window = tk.Tk()
frame1 = tk.Frame(master=None, width=200, height=100, bg="red")
frame1.pack(fill=tk.BOTH, side=tk.TOP, expand=False)
frame2 = tk.Frame(master=None, width=100, height=50, bg="yellow")
frame2.pack(fill=tk.BOTH, side=tk.TOP, expand=False)
frame3 = tk.Frame(master=None, width=50, height=25, bg="blue")
frame3.pack(fill=tk.BOTH, side=tk.TOP, expand=False)
window.mainloop()
fill
and side
interactions
Problem is I expect tk.BOTH to fill vertically when I drag window down, but it does not (seen by grey background of window). It only fills horizontally.
When i change all 3 frames’ sides from tk.TOP
to tk.LEFT
, it fills vertically but not horizontally
Based on above 2 experiments, is it true side
value changes behavior of fill=tk.BOTH
, making it work only in 1 direction each time?
To further test, with side=tk.LEFT
, I changed tk.BOTH
in all frames to tk.Y
, then tk.X
.
tk.Y behaves the same as tk.BOTH. tk.X still does not fill horizontally, but now also does not fill vertically (as expected)
fill
and expand
interactions
If I set all 3 frames expand = True
, all the previously failed fills are now successfully filling.
I’m confused did the fill=tk.BOTH
now work because of expand=True, or tk.BOTH
still does not work, and expand took over the role of filling for the failed direction?
If the latter, what’s the purpose of tk.BOTH
since it always fails to fill in 1 direction depending on side
, and depends on expand=True to make up for it’s failures?