tkinter, grid and resize

Tim Evans tim at paradise.net.nz
Sat Jun 24 21:12:53 EDT 2000


Bob van der Poel <bvdpoel at uniserve.com> writes:

> I'm having a problem getting widgets managed by grid to resize
> themselves when the screen size changes. This is easy to do using the
> pack manager and 'expand', however 'expand' doesn't exist in grid and
> the docs seem to indicate that the 'news' sticky option should do the
> same. The following snippet creates a text widget with scrollbars. If
> you resize the main window, the widgets do not resize....
> 

You need to use the grid_rowconfigure and grid_columnconfigure
methods of the containing frame, specifically the 'weight=' option.

> from Tkinter import *
> 
> root=Tk()
> 
> ys = Scrollbar(root)
> xs = Scrollbar(root)
> 
> dsp = Text(root, yscrollcommand=ys.set, xscrollcommand=xs.set)
> xs.config(orient='hor', command=dsp.xview)
> ys.config(orient='vert', command=dsp.yview)
> xs.grid(row=1, column=1, sticky=E+W)
> ys.grid(row=0, column=0, sticky=N+S)
> dsp.grid(row=0, column=1, sticky=N+S+E+W)

root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(1, weight=1)

> 
> root.mainloop()
> 
> What am I don't wrong? I've tried to insert columnspan stuff and played
> with the weight options--but I don't seem to be getting it.
> 
> Thanks.

See the Tcl/Tk documentation under 'grid' for more information,
including other useful options for the rowconfigure and
columnconfigure methods.

-- 
Tim Evans



More information about the Python-list mailing list