If I’m trying to create a window or prompt a file dialog in the IDLE shell, nothing opens and the shell restarts. Is this a bug of some kind? I can’t find anything about it. I’m new to PyQt (and Python in general) but had been able to get tutorials to work correctly. The last day or so, if I open IDLE and import PyQt4, QtGui, etc and then run something simple like QFileDialog.getOpenFileName, the shell just restarts. Any ideas?
Share
You need to have a
QApplicationbefore you can use anything else from PyQt. Try rereading some of the tutorials you followed, or do a few more. This one for example.In the first code sample of the above tutorial, pay special attention to these lines (I’ve included the comments from the tutorial for convenience):
and
It appears you might have forgotten about these. Or maybe you haven’t realized that this means that you normally can’t use PyQt with a running event loop in the interactive shell. However, there is a trick for that, see here.