Tkinter: can widgets automatically resize to fit parent?

Andy Gimblett gimbo at ftech.net
Wed Mar 6 12:31:54 EST 2002


On Wed, Mar 06, 2002 at 06:04:45PM +0000, Eric Brunel wrote:

> you didn't actually display your Application in its master. The
> "Frame.__init__" stuff does not suffice: you should also do a pack
> or grid.  Then, inserting the button in self.master rather than in
> self should be useless...

OK, I think I get that...  The Application object was just dangling,
with one of its children attached to the root instead, huh?

> you configured your button to take the size of its parent cell using
> the sticky option, but you didn't tell the cell to take the whole
> space in its parent. This should be done via the grid_rowconfigure
> and grid_columnconfigure methods to set the weight option on the
> cell.

I wondered if there was something like that going on, but couldn't see
the mechanism.  So, am I going to have to call grid_rowconfigure and
grid_columnconfigure for every row/column in the grid (ie as I add
more widgets - obviously the example was deliberately trivial)?  It
seems strange to make calls to the container telling it how to expand
its cells, rather than to the widgets that go into the cells, but
that's probably just because I was polluted by Delphi back in the
past.  :-/

> So here is a code that does what you want:

[snip]

Great stuff - thanks.  I will examine and read more.

I note that the following also seems to do what I want, and will also
read more along these lines:  ;-)

    def __init__(self, master):

        Frame.__init__(self, master)
        self.pack(fill=BOTH, expand=1)

        self.action = Button(self, text="Go")
        self.action.pack(fill=BOTH, expand=1)


Many thanks!

-Andy

-- 
Andy Gimblett - Programmer - Frontier Internet Services Limited
Tel: 029 20 820 044 Fax: 029 20 820 035 http://www.frontier.net.uk/
Statements made are at all times subject to Frontier's Terms and
Conditions of Business, which are available upon request.




More information about the Python-list mailing list