In this PyQt5 Tutorial we are going to learn about Create Python GUI Applications with Qt, when you want to build GUI applications with Python, there are different and powerful libraries that you can use for building Python GUI Application, one of them are PyQt5, so PyQt5 is Python module that allows you to create desktop applications with graphical user interfaces (GUI) using Qt framework. Qt framework is powerful and widely used C++ toolkit for building cross platform applications with native look and feel. In this tutorial we will learn how to use PyQt5 to create Python GUI applications with Qt.
Installing PyQt5 : before we can start building python applications with PyQt5, we need to install the module. you can install it using pip by running this command in your command prompt:
1 |
pip install PyQt5 |
Creating Basic PyQt5 Application: for creating basic PyQt5 application, first of all we need to import necessary modules and create QApplication object, which manages the application’s event loop and handles user input. we also need to create QMainWindow object which serves as the main window for our application.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import sys from PyQt5.QtWidgets import QApplication, QMainWindow #create QApplication object app = QApplication(sys.argv) #create your QMainWindow instance window = QMainWindow() #show the window window.show() #start the loop sys.exit(app.exec_()) |
This code creates basic application with main window that is initially hidden. the sys.exit() function is used to exit the application when the user closes the window.
Run the complete code and this will be the result.

Adding Widgets to the Window : Now that we have basic python gui application window, we can add widgets to it. PyQt5 provides different widgets that we can use to create our user interface. this is an example code to add label widget to the main window:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel #create QApplication instance app = QApplication(sys.argv) #create QMainWindow instance window = QMainWindow() #set the window title window.setWindowTitle('GeeksCoders.com') #set the geometry of the window (x,y,width and height) window.setGeometry(100, 100, 400, 300) #create a label label = QLabel('Geekscoders.com', window) #move the label label.move(50, 50) #show the window window.show() #start the loop sys.exit(app.exec_()) |
This code creates label widget with the text “Geekscoders.com” and adds it to the main window at the position (50, 50). setWindowTitle() function is used to set the title of the main window, and the setGeometry() function is used to set its size and position.
Run the complete code and this will be the result.

Handling User Events: In PyQt5 we can handle user events such as button clicks or keyboard presses using signals and slots. Signals are emitted when particular event occurs and slots are functions that are executed in response to these signals. this is an example code to handle button clicks using signals and slots:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton app = QApplication(sys.argv) window = QMainWindow() window.setWindowTitle('GeeksCoders.com') window.setGeometry(100, 100, 400, 300) button = QPushButton('Click Me!', window) button.move(50, 50) def button_clicked(): print('Button Clicked!') button.clicked.connect(button_clicked) window.show() sys.exit(app.exec_()) |
This code creates button widget with the text “Click Me” and adds it to the main window at the position (50, 50). button_clicked() function is executed when the button is clicked and it prints message to the console. clicked signal of the button is connected to the button_clicked() slot using the connect() function.
Run the complete code and this will be the result.

In this article we have learned how to use PyQt5 to create Python GUI applications with Qt. we have started by installing the module and creating basic application window. after that we added widgets to the window and learned how to handle user events using signals and slots.
Learn More on Python
- Python-Docx: Creating Microsoft Word Documents with Python
- Python and Microsoft Word: A Beginner’s Guide to Automating Documents
- How to Install docx2python: Python Library for Word Documents
- Merge Microsoft Word Documents with Python Docxcompose
- Asynchronous Web Development with Python and aiohttp
- Python Treq: An Introduction to a Powerful HTTP Client Library
- Introduction to Python httplib2 Library
- An Introduction to Python’s urllib Library
- Python httpx: A High-Performance HTTP Client for Python 3