Why does pack and grid override the parent widget's predefined dimensions?

后端 未结 1 495
孤独总比滥情好
孤独总比滥情好 2021-01-28 09:34

I noticed each time I create a Tkinter widget and set its dimensions either during the widget instantiation or by configuring them later, these last ones take no effect as soon

相关标签:
1条回答
  • 2021-01-28 10:05

    Both grid and pack have a "shrink to fit" behavior -- the size of a container widget (typically a frame or the root window) is determined by the size of the children. This feature is called geometry propagation. You can turn this feature off, but 99% of the time this feature will give you the best results.

    Tkinter's philosophy is that you should correctly size the widgets that the user interacts with (Entry, Button, etc), and then let pack and grid figure out the right size of the frames and windows.

    Tkinter does a very good job of this, and in my experience makes creating layouts much easier because you spend less time trying to compute how much space you need and more time focusing on what the user will actually interact with.

    0 讨论(0)
提交回复
热议问题