Hello World
这个基本代码将使用 PyQt4 启动一个 Hello world
GUI 窗口:
import sys
from PyQt4 import QtGui
# create instance of QApplication
app = QtGui.QApplication(sys.argv)
# create QLabel, without parent it will be shown as window
label = QtGui.QLabel('Hello world!')
label.show()
# start the execution loop of the application
sys.exit(app.exec_())
这是使用 PyQt5 的相同代码。
import sys
from PyQt5 import QtWidgets
# create instance of QApplication
app = QtWidgets.QApplication(sys.argv)
# create QLabel, without parent it will be shown as window
label = QtWidgets.QLabel('Hello world!')
label.show()
# start the execution loop of the application
sys.exit(app.exec_())