tkinter: grid: expand and fill

Dan Kuchler kuchler at ajubasolutions.com
Mon Jul 24 19:03:09 EDT 2000


Keith Murphy wrote:
> 
> here's my example that still doesn't work:
> 
> class scrolledtext:
>     def __init__(self, master, scrollflags=(NO,NO)):
>         stxt = self.stxt = Frame(master)
>         txt = Text(stxt, height=5)
>         txt.grid(row=0, column=0, sticky=NSEW)
> 
>         if scrollflags[0]:
>             hbar = Scrollbar(stxt, orient=HORIZONTAL, takefocus=NO,
> width=10)
>             hbar.grid(row=1, column=0, sticky=W+E, columnspan=2)
>             txt.config(xscrollcommand=hbar.set)
> 
>         if scrollflags[1]:
>             vbar = Scrollbar(stxt, orient=VERTICAL, takefocus=NO,
> width=10)
>             vbar.grid(row=0, column=1, sticky=N+S)
>             txt.config(yscrollcommand=vbar.set)
> 
> ...called with the following line:
> statustxt = scrolledtext(sbar, (YES, YES))
> where sbar is a frame.
> 
> i want the text to fill the area except for the spots where the scroll
> bars are.  i also want the window to be able to be resized.  help!
> 
> thanks,
> -->keith
> 
> > > is there a way to make a frame, that's been formatted using grid,
> > expand
> > > to fill the space it is given?

In tcl/tk this would be solved by making column 0 and
row 0 have a weight of 1 and by making column 1 and row
1 have a weight of 0.

This would be done using 'grid columnconfigure' and 'grid
rowconfigure' in combination with the sticky code that you
already added.

If you can find the python equivalent of setting the weight
of the columns and rows, I think your code should work.

--Dan



More information about the Python-list mailing list