New to Tkinter GUI building

Eric Brunel eric_brunel at despammed.com
Fri Mar 2 03:34:08 EST 2007


On Thu, 01 Mar 2007 21:01:40 +0100, Adam <adamgarstang at googlemail.com>  
wrote:

> Ok the window has resized but the elements inside are still like they
> were, so they are going off the edge on the window. How can I get
> these to resize? I have put sizes on the frames they are in. Sorry to
> keep asking but I'm flying blind here, I have checked the python site
> and the intro to tkinter which are both usually good for this kinda
> thing.

[snip code]

I've not tried your code, but it seems to be missing some grid  
configuration. Basically, you need to tell all containers what row(s) or  
column(s) will grow or shrink when the container itself grows or shrink.  
This is done by calling the grid_rowconfigure and grid_columnconfigure  
methods on the container, passing the weight option:
container.grid_rowconfigure(0, weight=1)
means that when the container size changes, all rows will (try to) stay  
the same, except row number 0 which will adapt its size to the new  
container size. (This is actually a bit more complicated than that, but it  
should suit your needs for the moment).

Since the default weight for all rows and columns is 0, meaning "don't  
change your size", the behavior you see is quite normal.

A little tip: things are usually a bit more complicated when you have  
several levels of frames within each other. Specifying a "flashy"  
background color for frames can help you to figure out which one does  
change its size as you want. Use bg='red' or bg='green' in your Frame  
creations to make obvious where they are; you'll see far clearly what  
happens when you resize your window.

A few short notes:
- You don't need at all to put all your widgets in attributes. Unless  
you'll have to access the widget itself later (e.g to change it state or  
color, or whatever), putting it in a local variable is fine.
- In your code, it appears to me that self.mainWindow is not needed. The  
Tk instance (self.top) *is* the top-level window and is a valid container  
for whatever widgets you need. Having a Frame inside it will only cause  
layout problems. I'd do:
   self.mainWindow = tk.Tk()
   self.mainWindow.geometry('700x400+0+0')
   self.labAll = tk.Label(self.mainWindow, text="All Files/Folders:")
   ...

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"



More information about the Python-list mailing list