Care must be taken in packing the widgets to ensure that the desired layout is obtained. The pack
command provides a convenient method of geometry management for simple forms. However, for more complex forms, the grid
command allows you to manage your widget placement by creating and configuring rows and columns for widget placement.
To illustrate this better, think of the grid as being similar to a table or a spreadsheet, as it contains rows and columns, as follows:
Column 0 |
Column 1 |
Column 2 | |
Row 0 | |||
Row 1 | |||
Row 2 |
Please note that the column and row numbering are zero-based. This is the grid layout that we will use in the following example.
Based on the options provided, when invoked, the grid
command assumes several forms. The syntactical options are as follows:
Option |
Interpretation |
---|---|
|
Behaves in the same manner as grid configure. |
|
Controls placement of the grid itself. Acceptable values are |
|
When no arguments are provided this command will return the size of the bounding box in pixels as a four digit integer. The first two are the pixel offset for the top-left corner from the parent. The second two are the size of the bounding box (width and height). If a single column and row are provided, the bounding box for the individual cell is returned. If two column and row pairs are provided the values for the bounding box spanning the rows is returned. |
|
Query or set the properties of the column referenced for the parent provided. The valid options are:
|
|
Accepts one or more widgets followed by option/value pairs to configure. Acceptable values are:
|
|
Remove one or more widgets from the grid. Configuration values for the widget specified are discarded. If the widget is then returned to the grid all desired configurations must be specified. |
|
Returns a list containing the option/value pairs for the current configuration of the widget referenced. |
|
Based on the screen location as referenced by |
|
Remove one or more widgets from the grid. Configuration values for the widget specified are not discarded. If the widget is then returned to the grid, all the desired configuration is reapplied. |
|
Returns the size of the grid as column the row. |
|
If no options are provided, this command will return a list of all widgets contained within master. The acceptable values for option are |
In the following example, we will create several widgets and arrange them using the grid
command. Enter the following commands:
1 % entry .e -width 10
.e
2 % label .1 -text ONE
.1
3 % label .2 -text TWO
.2
4 % label .3 -text THREE
.3
5 % button .b -text Exit -command exit
.b
6 % grid .e -row 0 -column 2
7 % grid .1 -row 1 -column 0
8 % grid .2 -row 1 -column 1
9 % grid .3 -row 1 -column 2
10 % grid .b -row 2 -column 2
18.222.184.200