By default, both pack
and grid
shrink or grow a widget to fit its contents, which is what you want 99.9% of the time. The term that describes this feature is geometry propagation. There is a command to turn geometry propagation on or off when using pack
(pack_propagate
) and grid
(grid_propagate
).
Since you are using pack
the syntax would be:
f.pack_propagate(0)
or maybe root.pack_propagate(0)
, depending on which widgets you actually want to affect. However, because you haven't given the frame height, its default height is one pixel so you still may not see the interior widgets. To get the full effect of what you want, you need to give the containing frame both a width and a height.
That being said, the vast majority of the time you should let Tkinter compute the size. When you turn geometry propagation off your GUI won't respond well to changes in resolution, changes in fonts, etc. Tkinter's geometry managers (pack
, place
and grid
) are remarkably powerful. You should learn to take advantage of that power by using the right tool for the job.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…