Calling Python-tk code from C/C++

David Boddie david at boddie.org.uk
Tue Jan 27 17:58:18 EST 2009


On Tuesday 27 January 2009 18:29, Gabriel Genellina wrote:

> En Tue, 27 Jan 2009 07:42:01 -0200, Rajorshi Biswas <rajorshi at in.com>
> escribió:
> 
>> Hello all, This is my first post to this mailing list. Our requirement
>> is to invoke a Tkinter python panel from a C++ GUI app where both GUI
>> windows would run in 2 separate threads. We have written a sample PyQt
>> application which calls this Tk panel using something like this:class
>> TkPanel(threading.Thread):def run(self): # call showPaneldef
>> showPanel():# create window = Tk.Tk() window.mainloop()def start():t =
>> TkPanel()t.start()Now we call this from our main python code:def
>> startPanel(self): import tkPanel tkPanel.start() # this calls
>> tkwindow.mainloop() in a separate thread.This works absolutely fine when
>> the invoking app is Python.
> 
>  From the above description I don't see where PyQt is involved. Do you
> really want to mix Qt and Tk in the same application? I don't think they
> could coexist...

It's been made to work before:

  http://www.froglogic.com/pg?id=Products&category=tq&sub=overview

Since Rajorshi has posted this to the PyQt list and qt-interest, in addition
to this list, maybe it's time to take a look at the problem more closely:

  http://www.riverbankcomputing.com/pipermail/pyqt/2009-January/021649.html

Without being able to see behind the scenes at what is happening with each
framework, we can only say that it looks like some threading issue (possibly
just an implementation detail of either framework) is causing control to
be returned to the interpreter from within the wrong thread. Maybe it's
just an issue of competing event loops and Python C API usage in the
extension modules.

I found that, using Ubuntu 7.10, the windows stopped receiving repaint
events, making it look like the application had frozen. Basically, I think
some kind of Qt-Tk event loop integration is required if widgets from both
frameworks are going to coexist within the same process.

David



More information about the Python-list mailing list