The program “Hello World” with PyQT, a module for creating desktop apps. In this article you’ll learn how to create the “hello world” app in PyQt.
If you want to make a desktop app or graphical user interface, PyQT is a good module for that.
Before starting this tutorial, make sure you have PyQt5 installed.
Related Course: Create GUI Apps with Python PyQt5
PyQt Hello World
Example
The program below creates the “hello world” window.
1 | import sys |
If you are new to Python PyQt, then I highly recommend this book.
How it works
PyQT is initialized with the code below:
1 | app = QApplication(sys.argv) |
Text cannot be added immediately to a window. It has to be added to a label.
A label is a widget that can show text or images. These lines create a QLabel, set the labels text and position (horizontal, vertical).
1 | textLabel = QLabel(widget) |
Now you should show the window.
Set the starting position (50,50) and the window size (320,200) with the method setGeometry().
1 | widget.setGeometry(50,50,320,200) |
Then you want to show the window! Give it a title with setWindowTitle() and display it with show().
1 | widget.setWindowTitle("PyQt5 Example") |