Here’s the sample code that I want to run:
import sys from PyQt4 import QtGui app = QtGui.QApplication(sys.argv) window = QtGui.QWidget() window.setGeometry(0, 0, 500, 300) window.setWindowTitle("Dummy PyQt file") window.show()
The file is saved as sample.py
. The following command isn’t working:
$ python ./sample.py
Advertisement
Answer
You need to start the Qt event loop by calling app.exec_()
once you have initialised the widgets and called show()
on your main window.
import sys from PyQt4 import QtGui app = QtGui.QApplication(sys.argv) window = QtGui.QWidget() window.setGeometry(0, 0, 500, 300) window.setWindowTitle("Dummy PyQt file") window.show() app.exec_()