pyqt 你好,世界

示例

此基本代码将使用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_())