Reputation: 1401
After several years using python this is the first time that it happens that trying some code in the python prompt, line by line, has different result than running it in a script file.
The code is simple:
import os, sys
from PyQt4 import QtGui, QtCore, uic
app = QtGui.QApplication(sys.argv)
splash=QtGui.QSplashScreen(QtGui.QPixmap("/home/pippo/splashscreen.jpg"))
splash.show()
print "hello!"
time.sleep(10)
If I enter the lines one by one in the python prompt (version 2.7.3) after the line splash.show() I can see the image displayed on the screen, If I instead run it in a script the image is not displayed while I can see that the print that follows the splash is properly on the terminal.
Can anybody help me to understand what could be the cause of the two different behaviours?
Upvotes: 1
Views: 200
Reputation: 2947
From the documentation:
PyQt4 installs an input hook (using PyOS_InputHook) that processes events when an interactive interpreter is waiting for user input. This means that you can, for example, create widgets from the Python shell prompt, interact with them, and still being able to enter other Python commands.
As for your script you have to call app.exec_() for Qt event loop to start (and show the splash). The same happens in C++ Qt program, you won't get any GUI without the event loop.
Upvotes: 6