2.2. Grid

The grid geometry manager divides the window into a grid composed of columns and rows starting at 0,0 in the upper left-hand corner. Figure 2.26 shows a sample grid.

Figure 2.26. Diagram showing window divided into grid

Rather than using the sides of a window as reference points, grid() divides the screen into columns and rows. It looks a lot like a spreadsheet doesn't it? Each widget is assigned a grid cell using the options available to grid().

The grid() method takes a list of widgets instead of operating on only one widget at a time.[1] Here is the generic usage:

[1] Several people have told me that pack can also take a list of widgets. I didn't cover this because it is not how pack is normally used.

$widget1->grid( [ $widget2, ... , ] [ option => value, ... ] );

A specific example:

$widget1->grid($widget2, $widget3);

Instead of using three separate calls, you can use one grid()call to display all three widgets. You can also invoke grid() on each widget independently just as you can pack(). Each call to grid() will create another row in the window. So in our example, $widget1, $widget2, and$widget3 will be placed in the first row. Another call to grid would create a second row. This is what happens when you do not specify any additional options to the grid() call.

For greater control, you can specify explicit -row and -column options for each widget in the window. ...

Get Learning Perl/Tk now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.