Practical Programming in Tcl and Tk (4th Edition)

Category: Programming
Author: Ken Jones
3.8
This Month Stack Overflow 1

Comments

by anonymous   2019-01-13

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

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.

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.