[pygtk] Can't run PyGTK more than once from embedded Python
Patrick K. O'Brien
pobrien at orbtech.com
Sun Jan 8 06:18:46 WST 2006
Romain Behar wrote:
> Many thanks!
>
> Both
> self.window.connect('delete-event', gtk.main_quit)
> and
> self.window.connect('destroy', gtk.main_quit)
> work.
Yes. I'm new to pygtk myself, but from what I've seen the difference
appears to be one of fashion, or simply arbitrary. The two events have
subtle differences, but which is hooked up to gtk.main_quit seems to be
fairly arbitrary in most simple use cases. To me, destroy seems like
the more logical candidate. But I'm nitpicky.
> Now, the script quits, but running it again outputs
> the following error:
>
> Traceback (most recent call last):
> File "<string>", line 7, in ?
> File
> "/usr/lib/python2.3/site-packages/gtk-2.0/gtk/__init__.py",
> line 38, in ?
> import gdk # this is created by the _gtk import
> ImportError: No module named gdk
Well, gdk (and most of pyGTK, for that matter) are actually DLLs in the
form of .pyd files. On Windows it isn't unusual for DLLs to cause
problems. I ran into similar problems trying to do things in Python
embedded in a C++ program. I was never able to resolve those issues.
So while it might *seem* quite natural to be able to run pygtk from
within a Python interpreter embedded in a GTK program, don't be
surprised if you run into troubles with anything in the form of a .pyd
file. Embedded Python simply isn't capable of dealing with
sophisticated scripting. Anything in pure Python is usually okay.
Hate to burst your bubble, but I've spent a lot of time trying to
accomplish something very similar. You are much better off writing your
main interface in Python, and making use of C modules from the Python
side, rather than the reverse.
Hope that helps. If you find a way to make this work, I'd love to hear
about it. :-)
--
Patrick K. O'Brien
Orbtech http://www.orbtech.com
Schevo http://www.schevo.org
Louie http://louie.berlios.de
More information about the pygtk
mailing list