“网格"与“网格"之间的区别在于:和“包装"几何经理 [英] Difference between "grid" and "pack" geometry managers

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

问题描述

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 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.

不能将网格和具有共同父级的窗口小部件一起使用.您的应用程序可能会工作,但是当每个管理员尝试布局小部件时,它更有可能陷入无限循环,然后其他人注意到小部件会更改大小并尝试进行调整等.

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非常适合进行绝对定位(即:将小部件放置在给定的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).

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

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天全站免登陆