Running a Qt program from the Canopy GUI


If you run a naive Qt application in the Canopy GUI (or in any IPython PyLab or Matplotlib environment), you are likely to get a complaint from QApplication that an event loop is 


By default, Canopy's IPython panel runs in "PyLab" mode. IPython's Pylab mode and Matplotlib mode each starts an event loop for the IPython front end (in this case, Canopy), which allows you to interact at the IPython command line with your GUI, a very powerful feature.


Your Qt program must check whether a QApplication (event loop) already exists, and if it does, then use the existing one instead of trying to create a new one.

Here's an simple example which will run with or without Pylab.

import sys
from PySide import QtGui
app = QtGui.QApplication.instance()
standalone = app is None
if standalone:
    app = QtGui.QApplication(sys.argv)
wid = QtGui.QWidget()
if standalone:
    print "We're back with the Qt window still active"
Have more questions? Submit a request


Powered by Zendesk