Name

grid

Synopsis

                        w.grid(**grid_options)

Delegates geometry management to the gridder. grid_options may include:

column

The column to put w in; default 0 (leftmost column).

columnspan

How many columns w occupies; default 1.

ipadx, ipady

How many pixels to pad w, horizontally and vertically, inside w’s borders.

padx, pady

How many pixels to pad w, horizontally and vertically, outside w’s borders.

row

The row to put w in; default the first row that is still empty.

rowspan

How many rows w occupies; default 1.

sticky

What to do if the cell is larger than w. By default, with sticky='', w is centered in its cell. sticky may be the string concatenation of zero or more of N, E, S, W, NE, NW, SE, and SW, compass directions indicating the sides and corners of the cell to which w sticks. For example, sticky=N means that w sticks to the cell’s top and is centered horizontally, while sticky=N+S means that w expands vertically to fill the cell and is centered horizontally.

For example:

import Tkinter
root = Tkinter.Tk( )
for r in range(3):
    for c in range(4):
        Tkinter.Label(root, text='R%s/C%s'%(r,c),
            borderwidth=1 ).grid(row=r,column=c)
root.mainloop( )

displays 12 labels arrayed in a 3 × 4 grid.

Get Python in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.