Tkinter vs. PyQt

Matthew Dixon Cowles matt at mondoinfo.com
Tue Aug 28 04:06:02 CEST 2001


On 27 Aug 2001 05:18:18 -0700, Paul Rubin <phr-n2001 at nightsong.com>
wrote:

>but at least with those docs, there were some simple things I wasn't
>able to figure out how to easily do.  For example, I don't see an
>easy way to make the buttons in a column come out the same size
>(though their labels were of different lengths).

Paul,
I've got a GUI MUA (currently working on version 0.4) that uses
Tkinter so I can assure you that there's a fair amount of stuff in
Tkniter that's maddening. On the other hand, there's a lot of support
for Tkinter. Pmw (http://pmw.sourceforge.net/) is very useful and
there are lots of folks who can answer Tkinter questions.

Regarding the buttons, you can specify a width:

>>> from Tkinter import *
>>> r=Tk()
>>> b=Button(r,text="a",width=10)
>>> b.pack()
>>> b=Button(r,text="ab",width=10)
>>> b.pack()
>>> b=Button(r,text="abc",width=10)
>>> b.pack()

That's fine if you want a button that's the same width as another
button but doesn't do you much good if you want a button that's the
same width as something that's measured in dots rather than
"characters". Here's a way to do that:

>>> from Tkinter import *
>>> r=Tk()
>>> f=Frame(r,width=100,height=30,bg="green")
>>> f.pack()
>>> bf=Frame(r,width=100,height=30)
>>> bf.pack_propagate(0)
>>> b=Button(bf,text="wibble")
>>> b.pack(fill=BOTH,expand=1)
>>> bf.pack()

That technique is in Fredrik's introduction but it's easy to miss.

The pack_propagate() call in there is what's interesting. It turns out
that Frames that don't contain anything stay the size that they were
created. But Frames that contain things (even if they were created
with their size specified) snap down to the smallest rectangle that
will contain the widgets inside them unless their pack_propagate()
method is called with a zero. Like I said, there's lots of stuff there
that's maddening.

Regards,
Matt



More information about the Python-list mailing list