“网格"与“网格"的区别和“包装"几何管理器 [英] Difference between "grid" and "pack" geometry managers

查看:22
本文介绍了“网格"与“网格"的区别和“包装"几何管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Tkinter 几何管理器 gridpack 之间的主要区别是什么?

What's the main difference between the Tkinter geometry managers grid and pack?

您的项目使用什么?

如果grid更好地对齐对象,pack的主要目的是什么?

If grid is better to align object, what the main purpose of pack?

推荐答案

grid 用于在网格中布置小部件.另一个答案说它覆盖了一个图形",这有点用词不当.它不覆盖任何东西,它只是沿着行和列的边界排列小部件.它非常适合创建表格和其他结构化类型的布局.

grid is used to lay out widgets in a grid. Another answer says it "overlays a graph" which is a bit of a misnomer. It doesn't overlay anything, it merely arranges widgets along row and column boundaries. It is great for creating tables and other structured types of layouts.

pack 将东西沿着盒子的侧面摆放.它擅长进行所有内容都在一行或一列中的布局(想想工具栏或对话框中的按钮行).它对于非常简单的布局也很有用,例如左侧的导航器和右侧的主工作区.它可用于创建非常复杂的布局,但在您完全理解打包算法之前它会变得棘手.

pack lays things out along the sides of a box. It excels at doing layouts where everything is on a single row or in a single column (think rows of buttons in a toolbar or dialog box). It's also useful for very simple layouts such as a navigator on the left and a main work area on the right. It can be used to create very complex layouts but it gets tricky until you fully understand the packing algorithm.

您不能将 grid 和 pack 与具有共同父级的小部件一起使用.您的应用程序可能可以工作,但更有可能进入无限循环,因为每个经理都尝试布局小部件,然后其他人注意到小部件改变大小并尝试调整等.

You cannot use both grid and pack with widgets that have a common parent. Your app may work but it is much more likely to get into an infinite loop as each manager tries to layout the widgets, then the other notices the widgets change size and try to adjust, etc. etc.

第三个管理是place.Place 非常适合进行绝对定位(即:将小部件放置在给定的 x/y)或相对位置(例如:将小部件放置在其他小部件的右边缘).

The third manage is place. Place is great for doing either absolute positioning (ie: place widget at a given x/y) or relative (eg: place a widget on the right edge of some other widget).

虽然您不能在同一个容器中混合使用 grid 和 pack(容器通常是一个框架),但您可以在单个应用程序中同时使用 grid 和 pack.这是非常非常普遍的,因为每个人都有优点和缺点.我经常使用两者.

While you cannot mix grid and pack within the same container (a container is typically a frame), you can use both grid and pack within a single application. This is very, very common since each has strengths and weaknesses. I use both on a regular basis.

这篇关于“网格"与“网格"的区别和“包装"几何管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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