Tkinter包的布局:松紧带类比 [英] Tkinter pack layout: Elastic band analogy

查看:79
本文介绍了Tkinter包的布局:松紧带类比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对我来说,使用包就像将所有小部件放在松紧带中一样,其含义是,该包将尝试将小部件保持在一个整洁的小区域.

Using pack has been described to me as like putting all of your widgets within an elastic band, the implications of this being that pack will try and keep your widgets in a small, neat area.

这个比喻与真相有多近,有什么矛盾之处?

How close is this analogy to the truth, and what are it's inconsistencies?

推荐答案

这种类比根本不准确. pack不会尝试将东西放在小而整洁的区域"中,它实际上与松紧带完全没有关系.

That analogy is not at all accurate. pack doesn't try to keep things in a "small, neat area", and it really has no relationship at all to an elastic band.

pack在概念上非常简单:它在父窗口小部件中未分配空间的边缘周围排列窗口小部件.想到这一点的最简单方法是,您从外面装满一个盒子,然后朝中间走去.使用pack,您将不断填充一个空洞,这就是为什么将其称为腔模型的原因.

pack is conceptually very simple: it arranges widgets around the edges of the unallocated space in a parent widget. The easiest way to think of this is that you're filling a box from the outside and working yourself toward the middle. Using pack, you are constantly filling an empty cavity, which is why this is referred to as the cavity model.

将窗口小部件放置在父窗口小部件的空腔内时,将其沿空腔的一侧放置.然后,小部件将占据该腔体的整个侧面.例如,如果使用选项side="left"包装某些东西,则小部件将占据型腔的整个左侧,然后为下一个小部件减小型腔的大小.如果父对象的宽度为1000像素,子对象的宽度为100像素,则将下一个子窗口小部件的型腔缩小为900像素.

When you place a widget inside the cavity of a parent widget, you are placing it along one of the sides of the cavity. The widget then takes up that whole side of that cavity. For example, if you pack something with the option side="left", the widget will take up the whole left side of the cavity, and then reduce the size of the cavity for the next widget. If the parent is 1000 pixels wide and the child is 100 pixels wide, you will have then reduced the cavity down to 900 pixels wide for the next child widget.

关于pack的工作方式的绝对最佳,最完整的描述可以在 Brent Welch,Ken​​ Jones和Jeffrey Hobbs 撰写的Tcl和Tk中的实用编程.可以在tcl/tk 打包手册页.它是从tcl/tk程序(相对于python/tkinter)的角度编写的,但是无论您使用哪种语言,其基本方面都是相同的.

The absolute best and most complete description of how pack works can be found in the book Practical Programming in Tcl and Tk, by Brent Welch, Ken Jones, and Jeffrey Hobbs. A concise but complete description of the packer algorithm can be found in the tcl/tk pack man page. It is written from the perspective of a tcl/tk program (versus python/tkinter) but the fundamental aspects are the same no matter which language you use.

这篇关于Tkinter包的布局:松紧带类比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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