In this article we want to learn How to Install PyQt5, so first of all let’s talk about PyQt5, also we will talk about the installation of PyQt5 also.
What is PyQt5?
PyQt5 a GUI library for Python, it is Python bindings for Qt application framework, Qt is developed by Qt Company. Qt is powerful and widely-used C++ framework for building cross-platform applications, including desktop, mobile and embedded systems using C++ programming language. Using PyQt5 you can create GUI applications using Qt framework. and PyQt5 is maintained by riverbank computing company.
How to Install PyQt5?
PyQt5 Installation is easy, you can just open your command prompt or terminal and write this command.
1 |
pip install PyQt5 |
To verify that PyQt5 has been successfully installed, you can run the following Python code in your terminal:
1 2 3 |
import PyQt5.QtCore print("PyQt6 installed successfully") |
Now let’s create a basic window in PyQt5
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 29 |
import sys from PyQt5.QtWidgets import QApplication, QWidget from PyQt5.QtGui import QIcon # Create subclass of QWidget to represent our window class MyWindow(QWidget): def __init__(self): super().__init__() # Set window title self.setWindowTitle('PyQt5 Window - Codeloop.org') #set window icon self.setWindowIcon(QIcon('codeloop.png')) # Set window size (width, height) self.setGeometry(100, 100, 400, 200) # Create an instance of QApplication app = QApplication(sys.argv) # Create an instance of MyWindow window = MyWindow() # Show the window window.show() # Start the event loop sys.exit(app.exec_()) |
This code creates a simple window with the title “PyQt5 Window – Codeloop.org” and a size of 400×200 pixels. When you run this code, a window will appear on your screen, and it will display the title with an icon. This is just a basic example to get you started with PyQt5 window creation. You can customize the window further by adding widgets, layouts and event handlers as needed for your application.
There is a good course in Udemy on PyQt6 in the name of (PyQt6 GUI Development with Qt Designer ) that you can join.
Run the code and this will be the result
Subscribe and Get Free Video Courses & Articles in your Email