To display a widget
on your application screen:w
w
.grid(option
, ...)
This method registers a widget
with
the grid geometry manager—if you don't do this, the
widget will exist internally, but it will not be
visible on the screen.w
Here are the options to the
.grid()
geometry management
method:
column | The column number where you want the widget gridded, counting from zero. The default value is zero. |
columnspan | Normally a widget occupies only one cell in
the grid. However, you can grab multiple cells
of a row and merge them into one larger cell by
setting the columnspan
option to the number of cells. For example,
would place
widget
in a cell that spans columns 2, 3, and 4 of row
0. |
ipadx | Internal x padding. This dimension is added inside the widget inside its left and right sides. |
ipady | Internal y padding. This dimension is added inside the widget inside its top and bottom borders. |
padx | External x padding. This dimension is added to the left and right outside the widget. |
pady | External y padding. This dimension is added above and below the widget. |
row | The row number into which you want to insert the widget, counting from 0. The default is the next higher-numbered unoccupied row. |
rowspan | Normally a widget occupies only one cell in
the grid. You can grab multiple adjacent cells of
a column, however, by setting the
rowspan option to the
number of cells to grab. This option can be used
in combination with the
columnspan option to grab
a block of cells. For example,
would place widget
in an area formed by merging 20 cells, with row
numbers 3–6 and column numbers 2–6. |
sticky | This option determines how to distribute any extra space within the cell that is not taken up by the widget at its natural size. See below. |
If you do not provide a
sticky
attribute, the default
behavior is to center the widget in the
cell.
You can position the widget in a corner of the
cell by using sticky=NE
(top
right), SE
(bottom right),
SW
(bottom left), or
NW
(top
left).
You can position the widget centered against one side of
the cell by using sticky=N
(top center), E
(right
center), S
(bottom center), or
W
(left
center).
Use sticky=N+S
to stretch
the widget vertically but leave it centered
horizontally.
Use sticky=E+W
to stretch
it horizontally but leave it centered
vertically.
Use sticky=N+E+S+W
to
stretch the widget both horizontally and vertically
to fill the cell.
The other combinations will also work. For
example, sticky=N+S+W
will
stretch the widget vertically and place it against
the west (left) wall.