In this tutorial you will learn how to use PyQt5 to create a hello world with Qt5 and Python. The example creates an application with a window containing one label. The structure looks like this:
This example is written on MacOS but should work on Windows and Linux. Start by opening a terminal and create a project:
mkdir helloworld
cd helloworld
Create a virtual environment and install PyQt5 in it:
python3 -m venv env
source env/bin/activate
pip install pyqt5
Create file main.py
and enter:
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel
app = QApplication(sys.argv)
window = QMainWindow()
window.setWindowTitle("Hello World")
label = QLabel('I must have left my house at 8, because I always do.')
label.setMargin(20)
window.setCentralWidget(label)
window.show()
app.exec_()
Start the app in the Terminal with:
python3 main.py
The result should look like this.