Replacement for pygtk?

Grant Edwards grant.b.edwards at gmail.com
Fri Sep 4 17:24:10 EDT 2020


On 2020-09-03, Michael Torrie <torriem at gmail.com> wrote:
> On 9/3/20 1:17 PM, Grant Edwards wrote:
>> On 2020-09-03, Grant Edwards <grant.b.edwards at gmail.com> wrote:
>>> [...]
>>>
>>> Is pygobject the replacement for pygtk?
>> 
>> It seems to be.  I've started porting my pygtk app, and it's going
>> pretty smoothly.  I've already got my two custom widgets working.
>> Oddly, the main module provided by the gobject package is called "gi".
>
> It stands for "gobject introspection."

That's what I (later) suspected.

> The nice thing about the gi module is it can wrap any gobject-based
> library, not just GTK+ proper.  So if someone made a custom widget
> in Vala, for example, you could access it via gi.  It's a neat
> idea. My only problem with it is the resulting Python API is not
> always as pythonic as pygtk code was.

I noticed that right away.  In pygtk, most methods (e.g. .pack_start)
had named arguments with well chosen defaults. The vast majority of
the time, I only supplied one argument for the pack_start() call.
With gi's implementation of pack_start, there are no named parameters:
they're all positional. You have to specify all four of them every
time, even if the last three are False,False,0 95% of the time.  And
the lack of names makes it impossible to figure out from reading the
application source code what those last three actually mean.  [The
first argument is obvious in context.]

I assume that difference is because pygtk was hand-written and gi is
built auto-magically using SWIG or something like that?

> I can't think of any specific examples at the moment, however.  It's
> pretty much good enough to not care too much.

For native Linux apps I definitely prefer Gtk.  The other choices are

 * WxPython ­- It's bigger and far more complex than pygtk/gi and the
   extra complexity doesn't ever seem to buy me anything except
   MS-Windows compatibility [which did matter for a few of the apps I
   used to maintain].  The last time I looked into Gtk on Windows, it
   didn't sound usable, but that was many years ago.

 * PyQt -- I run Gtk-centric Linux systems, and the second you try to
   use one Qt widget, it always seems to pull in hundreds of packages
   that take a week to build.

 * Tkinter -- It's ugly on Linux (yea, I know there are supposed to be
   ways to fix that, but they never seem to work for me).  All of the
   tkinter apps I maintain all seem to have one or two widgets with
   behavior that's counter-intuitive.  When you bundle a trivial
   tkinter app (e.g. with cx-freeze), it ends up huge unless you put
   in a great deal of work manually excluding stuff you don't need.

Back when there was a gtk version of Wireshark, I usually didn't have
any Qt stuff installed at all. I'm still trying to get _that_ knife
pulled out of my back.  How dare somebody give me (for free) something
tremendously valuable and useful in a slightly different flavor than I
would prefer. ;)

> Similar arguments can be made against PyQt as well.  Especially with
> PyQt the end result feels a bit like writing C++ with a python
> syntax.

--
Grant



More information about the Python-list mailing list