Name
grid
Synopsis
w.grid(**grid_options)
Delegates geometry management to the
gridder. grid_options may include:
-
column The column to put
win; default0(leftmost column).-
columnspan How many columns
woccupies; 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
win; default the first row that is still empty.-
rowspan How many rows
woccupies; default1.-
sticky What to do if the cell is larger than
w. By default, withsticky='',wis centered in its cell.stickymay 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 whichwsticks. For example,sticky=Nmeans thatwsticks to the cell’s top and is centered horizontally, whilesticky=N+Smeans thatwexpands 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.