[Tutor] A little Tkinter question

Marilyn Davis marilyn at deliberate.com
Fri Dec 17 18:26:40 CET 2004


On Wed, 15 Dec 2004, Gregor Lingl wrote:

> 
> 
> Marilyn Davis schrieb:
> > Hi Tutors,
> > 
> > I'm reviewing GUIs and wondering:
> > 
> > When you pack a component, and you specify fill = BOTH, how is this
> > different from expand = YES?
> > 
> Hi Marilyn,
> This is a bit tricky and hard to explain, so I recommend playing around 
> with this little program from John Grayson's Tkinter book:
> 
> from Tkinter import *
> 
> class App:
>      def __init__(self, master):
>          master.geometry("300x200")
>          fm = Frame(master)
>          Button(fm, text='Left').pack(side=LEFT, fill=BOTH, expand=1)
>          Button(fm, text='Center').pack(side=LEFT, fill=BOTH, expand=1)
>          Button(fm, text='Right').pack(side=LEFT, fill=BOTH, expand=1)
>          fm.pack(fill=BOTH, expand=YES)
> 
> 
> root = Tk()
> root.option_add('*font', ('verdana', 12, 'bold'))
> root.title("Pack - Example 9")
> display = App(root)
> root.mainloop()
> 
> Modify the three lines with Button(....).pack(...)
> for instance by setting expand = 0 (which is the default value)
> 
>          Button(fm, text='Left').pack(side=LEFT, fill=BOTH, expand=0)
>          Button(fm, text='Center').pack(side=LEFT, fill=BOTH, expand=0)
>          Button(fm, text='Right').pack(side=LEFT, fill=BOTH, expand=0)
> 
> or by tropping the fill option:
> 
>          Button(fm, text='Left').pack(side=LEFT, expand=1)
>          Button(fm, text='Center').pack(side=LEFT, expand=1)
>          Button(fm, text='Right').pack(side=LEFT, expand=1)
> 
> and so on.
> 
> These Examples are from Chapter 5, several others concerning the packer 
> can be found at:
> 
> https://secure.manning.com/catalog/view.php?book=grayson&item=source

Thanks for the pointer, Gregor.

I guess that the jist of it is that fill fills all available space.
And expand is about what happens to the widget when its master
expands.

But, the bit of the book I was looking at, I'm afraid, I found to be
difficult to follow.  There seemed to be outputs without matching
code, and the numbering system confused me.  And he pointed out the
difference between fill alone and fill with expand and they looked the
same.

I guess you are right.  One needs to experiment to get the desired
effect.

I have no desired effect.  I was just looking for intellectual
understanding.

Thank you.

Marilyn



> 
> Hope this helps
> Gregor
> 
> 
> > Thank you for any insight.
> > 
> > Marilyn Davis
> > 
> > 
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> > 
> > 
> 
> 

-- 



More information about the Tutor mailing list