为什么 pack 和 grid 会覆盖父窗口小部件的预定义尺寸?

Why does pack and grid override the parent widget#39;s predefined dimensions?(为什么 pack 和 grid 会覆盖父窗口小部件的预定义尺寸?)
本文介绍了为什么 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 会覆盖父窗口小部件的预定义尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Leetcode 234: Palindrome LinkedList(Leetcode 234:回文链接列表)
How do I read an Excel file directly from Dropbox#39;s API using pandas.read_excel()?(如何使用PANDAS.READ_EXCEL()直接从Dropbox的API读取Excel文件?)
subprocess.Popen tries to write to nonexistent pipe(子进程。打开尝试写入不存在的管道)
I want to realize Popen-code from Windows to Linux:(我想实现从Windows到Linux的POpen-code:)
Reading stdout from a subprocess in real time(实时读取子进程中的标准输出)
How to call type safely on a random file in Python?(如何在Python中安全地调用随机文件上的类型?)