为什么 pack 和 grid 会覆盖父小部件的预定义尺寸? [英] Why does pack and grid override the parent widget's predefined dimensions?

查看:27
本文介绍了为什么 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 的理念是您应该正确调整用户与之交互的小部件的大小(EntryButton 等),然后让 packgrid 找出框架和窗口的正确大小.

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 会覆盖父小部件的预定义尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆