Why does pack and grid override the parent widget#39;s predefined dimensions?(为什么 pack 和 grid 会覆盖父窗口小部件的预定义尺寸?)
问题描述
我注意到每次创建 Tkinter 小部件并在小部件实例化期间或通过 稍后配置,一旦我添加 子窗口小部件 在我使用 网格布局管理器.
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.
我的问题:
我宁愿问我的问题只是为了确定我是一个初学者:这是否意味着使用网格布局管理器会覆盖预定义的父小部件的尺寸?可以解释一下这是如何工作的吗?
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 ?
提前感谢您的澄清.
推荐答案
grid 和 pack 都具有缩小以适应"行为——容器小部件(通常是框架或根窗口)的大小由孩子的大小.此功能称为几何传播.您可以关闭此功能,但 99% 的时间此功能将为您提供最佳效果.
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 的理念是,您应该正确调整用户与之交互的小部件(Entry
、Button
等)的大小,然后让 pack
和 grid
确定框架和窗口的正确大小.
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 在这方面做得非常好,根据我的经验,创建布局变得更加容易,因为您花费更少的时间来计算您需要多少空间,而将更多的时间集中在用户将实际与之交互的内容上.
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.
这篇关于为什么 pack 和 grid 会覆盖父窗口小部件的预定义尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么 pack 和 grid 会覆盖父窗口小部件的预定义尺寸?


基础教程推荐
- Kivy 使用 opencv.调整图像大小 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01