[Tkinter-discuss] Grid
Mikael Olofsson
mikael at isy.liu.se
Thu Jan 4 12:58:57 CET 2007
Cam wrote:
> Any grid experts about? This minimal Tkinter program:
>
> from Tkinter import *
> root = Tk()
> root.geometry('640x480')
> B = Button(root)
> B.grid(column=0,row=0,sticky='wn')
> root.mainloop()
>
> produces a top-level with a Button centered in it. But I don't want the
> button in the middle, I want it in the upper left where you would sort
> of expect (0,0) to be. I thought the sticky option might do that but
> it doesn't.
You need to configure the grid, which is done using the methods
grid_columnconfigure and grid_rowconfigure. The following produces a
grid with two rows and two colums and places your Button where you want it:
from Tkinter import *
root = Tk()
root.geometry('640x480')
root.grid_columnconfigure(
0,
minsize=100,
pad=5,
weight=1
)
root.grid_columnconfigure(
1,
minsize=100,
pad=5,
weight=1
)
root.grid_rowconfigure(
0,
minsize=100,
pad=5,
weight=1
)
root.grid_rowconfigure(
1,
minsize=100,
pad=5,
weight=1
)
B = Button(root)
B.grid(column=0,row=0,sticky='wn')
root.mainloop()
HTH
/MiO
More information about the Tkinter-discuss
mailing list