Tkinter grid layout
Christopher Subich
spam.csubich+block at block.subich.spam.com
Thu Jul 7 21:32:53 EDT 2005
Eric Brunel wrote:
> So you should either make your MainWindow class inherit from Tk, which
> eliminates the unneeded container and the problems it may cause, or make
> sure the pack or grid on your MainWindow instance actually tells the
> container to grow with its container. With pack, it's quite easy: just
> do myWindow.pack(fill=BOTH, expand=1). With grid, it's a bit more
> complicated, since you will have to configure the grid on the container.
To expand on this, the grid-method uses a few calls that aren't
immediately obvious. Specifically, the containing object must have row
and columnconfigure called on them:
>>> r = Tk()
>>> g = Text(r)
>>> h = Entry(r)
>>> g.grid(row=1,sticky=N+S+E+W)
>>> h.grid(row=2,sticky=E+W)
>>> r.columnconfigure(0,weight=1)
>>> r.rowconfigure(1,weight=1)
>>> r.mainloop()
This creats a window containing a text widget above an entry widget.
Both will resize horizontally to fill the entire window, and the text
widget will resize vertically.
More information about the Python-list
mailing list