Do other Python GUI toolkits require this?

David Boddie david at boddie.org.uk
Tue Apr 24 18:46:47 EDT 2007


On Monday 23 April 2007 15:55, Kevin Walzer wrote:

> I had originally thought that learning PyObjC might preclude me from
> having to learn Objective-C, but that seems not to be the case. I have
> previously found the same to be true with PyQt and wxPython--not knowing
> the toolkits as they are implemented in C++ is a serious handicap.

I'm not so sure about that. Certainly, it's useful to be able to read C++
example code, but none of the examples you see should require more than
a basic proficiency in C++.

I started using PyQt before I had more than basic C++ skills, and I don't
think it slowed me down too much.

> I've even found this to be the case with Tkinter: understanding the Tcl
> implementation of Tk (which I do, because I am also a Tcl developer) is
> a huge advantage.
> 
> Am I wrong to conclude that, if you want to do GUI programming in
> Python, then some level of proficiency with another language is not just
> recommended, but almost required? This is the case at least in my
> experience. When I first started learning Python a couple of years ago,
> I spun my wheels with it for months, because I couldn't figure out where
> to get started with GUI programming.

Of the common toolkits and frameworks, I started using Tkinter because
that's what came with Python, but I can't say that I'm comfortable with
it. Once I started using PyQt, I started to forget Tkinter, and now I
don't have a reason to go back to using it.

> Finally I set Python aside and took 
> up Tcl/Tk for awhile--its simplicity in building GUI's is more
> beginner-friendly. (No "there's more than one way to do it"--there's
> only one way to do it, and that's Tk.)
> 
> Now, coming back to Python with the Tk model of GUI development burned
> in my brain, I appreciate the breadth of functions that Python
> supports--but I still find myself "dropping down into Tcl" (!) to
> assemble elements of my GUI's--either to write a Python wrapper, or
> figure out how to implement something in pure Python.

While this is one of the strengths of Tcl/Tk/Tkinter, I think this is a
relatively rare thing to do with other toolkits and frameworks. For example,
there are people writing wrappers around Qt-based classes, but the only
people writing wrappers for Qt or KDE classes are the bindings authors
themselves.

> I understand the argument for Python having lots of bindings to
> different GUI toolkits. If you are already proficient with a GUI toolkit
> in a compiled language (Gtk, wxWidgets, Cocoa, Qt) then presumably
> switching to Python will speed up your development--learning Python is
> easy if you already know C++, for instance, and usually the Python
> bindings are just a "thin wrapper" over the compiled bits.

Yes and no. The bindings may be thin, but there are often other advantages
that make the bindings subtly different/better to use than the underlying
toolkit/framework. :-)

>From memory, PyGTK is more natural to use the GTK+ on its own because Python
provides the object-oriented features that you don't get in C, though there
are C++ bindings to GTK+ as well.

Another example would be the way PyQt handles Qt's signals and slots. In C++
you need to declare these with specific signatures at compile time, but
that would be a bit restrictive in Python. The result is that PyQt lets you
define and connect arbitrary signals, slots and normal Python methods at
run-time. (Actually, you don't even need to define signals.)

So, even the thin wrappers contain some value other than simply enabling you
to use Python. :-)

> But if you come to Python from the other direction--you're a relative
> beginner and you want to learn GUI programming without the complexities of
> compiled languages--then it's a lot harder to get started, ironically.
> Even Tkinter is a challenge for someone who doesn't know Tcl. The basics
> are easy enough--buttons, menus, labels, images--but doing anything
> sophisticated, such as trees, column views, drag-and-drop, and so on,
> requires extensions that may or may not be implemented in Python.

I think that's a specific Tkinter problem in many ways. However, the
expectations of many new users have also increased since I wrote my first
GUI program in Python, and that also influences the way people respond to
the different solutions on offer.

David



More information about the Python-list mailing list