[Tutor] A little Tkinter question
Gregor Lingl
glingl at aon.at
Wed Dec 15 23:59:28 CET 2004
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
Hope this helps
Gregor
> Thank you for any insight.
>
> Marilyn Davis
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
--
Gregor Lingl
Reisnerstrasse 3/19
A-1030 Wien
Telefon: +43 1 713 33 98
Mobil: +43 664 140 35 27
Autor von "Python für Kids"
Website: python4kids.net
More information about the Tutor
mailing list