Two Tkinter questions

Greg Krohn gkrohn_NG_ at volucris.8m.com
Sat May 18 03:29:58 EDT 2002


"Mike Callahan" <mcalla at insightbb.com> wrote in message
news:MKhF8.27549$AU.39360 at sccrnsc02...
> Question #1
>
> I want a text widget to completely fill its space. I can do this in
tkinter
> using the pack geometery manager:
> text.pack(fill='both', expand=1)
> If I resize the window, the the text widget continues to fill the window,
> however if I use grid:
> text.grid(sticky='nsew')
> the text widget stays the same size if I make the window larger. Can't
grid
> do the same thing that pack can do?

You need to specify your widget's parent's weight for column and row. Use
parent.columnconfigure(column, weight), etc.

from Tkinter import *

parent = Tk()
Text(parent).grid(sticky='news')

#these two lines
parent.rowconfigure(0, weight=1)
parent.columnconfigure(0, weight=1)

root.mainloop()


You can change the weights around to achieve relative resizing (one widget
resizes twice as 'fast' as another). I have never had a reason to do that,
though.


greg






More information about the Python-list mailing list