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

蹲街弑〆低调 提交于 2020-01-30 11:28:06

问题


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 as I add child widgets inside the parent one where I organize them using the grid layout manager.

My question:

I rather ask my question just to be sure as I am a beginner: does this mean that using the grid layout manager overrides the predifined parent widget's dimensions ? May be some explanation on how this works ?

Thank you in advance for clarification.


回答1:


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.



来源:https://stackoverflow.com/questions/30029077/why-does-pack-and-grid-override-the-parent-widgets-predefined-dimensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!