Name
grid
Synopsis
w
.grid(**grid_options
)
Delegates geometry management to the
gridder. grid_options
may include:
-
column
The column to put
w
in; default0
(leftmost column).-
columnspan
How many columns
w
occupies; default1
.-
ipadx
,ipady
How many pixels to pad
w
, horizontally and vertically, insidew
’s borders.-
padx
,pady
How many pixels to pad
w
, horizontally and vertically, outsidew
’s borders.-
row
The row to put
w
in; default the first row that is still empty.-
rowspan
How many rows
w
occupies; default1
.-
sticky
What to do if the cell is larger than
w
. By default, withsticky='
',w
is centered in its cell.sticky
may be the string concatenation of zero or more ofN
,E
,S
,W
,NE
,NW
,SE
, andSW
, compass directions indicating the sides and corners of the cell to whichw
sticks. For example,sticky=N
means thatw
sticks to the cell’s top and is centered horizontally, whilesticky=N+S
means thatw
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.