This is an unofficial mirror of Tkinter reference documentation (based on Python 2.7 and Tk 8.5) created by the late John Shipman.
It was last updated in 2013 and is unmaintained. [More info]
To display a widget
on your
application screen:
w
w
.grid(option
=value
, ...)
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.
For the options, see Table 1, “Arguments of the w
.grid()
geometry
manager”.
Table 1. Arguments of the .grid()
geometry
manager
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.
|
in_ |
To register as a child of some widget , use in_= . The new parent must be a descendant of
the widget used when was created.
|
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=tk.NE
(top right), tk.SE
(bottom right), tk.SW
(bottom left), or tk.NW
(top left).
You can position the widget centered against one side
of the cell by using sticky=tk.N
(top
center), tk.E
(right center),
tk.S
(bottom center), or tk.W
(left center).
Use sticky=tk.N+tk.S
to stretch
the widget vertically but leave it centered
horizontally.
Use sticky=tk.E+tk.W
to stretch it
horizontally but leave it centered
vertically.
Use sticky=tk.N+tk.E+tk.S+tk.W
to stretch the widget
both horizontally and vertically to fill the
cell.
The other combinations will also work. For
example, sticky=tk.N+tk.S+tk.W
will
stretch the widget vertically and place it against
the west (left) wall.