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
You need to call app.exec_()
to start the Qt
event loop . Without it the program exits immediately before anything can be shown on screen.
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_()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.