pyqt Getting started with pyqt Hello world


Example

This basic code will launch a "Hello world" GUI window using PyQt4:

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_())

This is the same code using 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_())