Python | Introduction to PyQt5 Last Updated : 19 Dec, 2022 Comments Improve Suggest changes Like Article Like Report There are so many options provided by Python to develop GUI application and PyQt5 is one of them. PyQt5 is cross-platform GUI toolkit, a set of python bindings for Qt v5. One can develop an interactive desktop application with so much ease because of the tools and simplicity provided by this library. A GUI application consists of Front-end and Back-end. PyQt5 has provided a tool called 'QtDesigner' to design the front-end by drag and drop method so that development can become faster and one can give more time on back-end stuff. Installation: First, we need to install PyQt5 library. For this, type the following command in the terminal or command prompt: pip install pyqt5 If successfully installed one can verify it by running the code: >>>import PyQt5 PyQt5 provides lots of tools and QtDesigner is one of them. For this run this command: pip install PyQt5-toolsCreate your first app - This is a simple app having a single button in the window. After clicking that button a message will appear "You clicked me". Let's start. First of all, we need to find QtDesigner to create the front-end part. - QtDesigner is present at 'site-packages/pyqt5_tools' - For finding the location of site-packages write the following python code using any editor of your choice and then run:>>> import site >>> site.getsitepackages()- Run the application named 'designer'.A window will open as shown in the figure: select the 'Dialog without Button' option and click 'Create'At the left side of the designer there will be various widgets which can be dragged and dropped in our window according to our requirement.Find and drag-and-drop 'Push Button' and 'Label'. Change the text inside the widgets by right clicking it and selecting 'Change plain text'. Keep the text of the Label blank. We have created our front-end layout, just save it at your desired location.Remember, this file will have .ui as extension.We need to convert the .ui file into .py file to get the python form of the widgets and attach necessary event listeners to them.Converting .ui file into .py file:For this we have to go to sitepackages directory in terminal or command prompt and run the command as shown below. Getting the location of sitepackages is mentioned previously. >>> cd "C:\\Users\\......\\Programs\\Python\\Python36-32\\lib\\site-packages" [Location of sitepackages] >>> pyuic5 "C:\Users\......\FILENAME.ui"[Exact location of .ui file] -o " C:\Users\.......\FILENAME.py" [Location where want to put .py file] Finally we will add signals and slot in the python code to make it fully functional.widget.signal.connect(slot)A signal is emitted by widgets after the occurrence of a certain kind of event like a click, Double click, etc. A slot is any callable function which will perform some action after the occurrence of an event.Run the app and click the button. Below is the code - Python3 import sys from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(400, 300) self.pushButton = QtWidgets.QPushButton(Dialog) self.pushButton.setGeometry(QtCore.QRect(150, 70, 93, 28)) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(130, 149, 151, 31)) self.label.setText("") self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) # adding signal and slot self.pushButton.clicked.connect(self.showmsg) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) self.pushButton.setText(_translate("Dialog", "Click")) def showmsg(self): # slot self.label.setText("You clicked me") if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = Ui_Dialog() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec_()) Comment More infoAdvertise with us Next Article Python | Introduction to PyQt5 abhilekhnathdas111 Follow Improve Article Tags : Python Python-PyQt Python-gui Practice Tags : python Similar Reads Introduction to Python Pydantic Library In modern Python development, data validation and parsing are essential components of building robust and reliable applications. Whether we're developing APIs, working with configuration files, or handling data from various sources, ensuring that our data is correctly validated and parsed is crucial 6 min read Introduction to PyQtGraph Module in Python PyQtGraph is a graphics and user interface library for Python that provides functionality commonly required in designing and science applications. Its primary goals are to provide fast, interactive graphics for displaying data (plots, video, etc.) and second is to provide tools to aid in rapid appli 4 min read Introduction to Python qrcode Library We must have seen QR codes in real life. QR codes are now used everywhere. QR codes are those square-shaped, black-and-white patterns we see on products, posters, business cards, and even Wi-Fi routers. These are used to store information that can be quickly scanned and read by a smartphone or a QR 6 min read Python - How to save canvas in pyqt5? There are so many options provided by Python to develop GUI application and PyQt5 is one of them. PyQt5 is cross-platform GUI toolkit, a set of python bindings for Qt v5. One can develop an interactive desktop application with so much ease because of the tools and simplicity provided by this library 3 min read PyQt5 Input Dialog | Python PyQt5 provides a class named QInputDialog which is used to take input from the user. In most of the application, there comes a situation where some data is required to be entered by the user and hence input dialog is needed. Input can be of type String or Text, Integer, Double and item.Used methods: 2 min read PyQt5 QtSql - Python PyQt provides us UI features which can be useful in number of ways to build our applications using all the features and widgets of PyQt. Moreover PyQt provides us the facility to integrate our database in our application. We can integrate any database through it some of them are- MySQL, SQLITE etc. 3 min read Introduction to Python for Absolute Beginners Are you a beginner planning to start your career in the competitive world of Programming? Looking resources for Python as an Absolute Beginner? You are at the perfect place. This Python for Beginners page revolves around Step by Step tutorial for learning Python Programming language from very basics 6 min read Python GUI - PyQt VS TKinter A GUI toolkit contains widgets that are used to create a graphical interface. Python includes a wide range of Interface implementations available, from TkInter (it comes with Python, ) to a variety of various cross-platform solutions, such as PyQt5, which is known for its more sophisticated widgets 5 min read Creating Your Own Python IDE in Python In this article, we are able to embark on an adventure to create your personal Python Integrated Development Environment (IDE) the usage of Python itself, with the assistance of the PyQt library. What is Python IDE?Python IDEs provide a characteristic-rich environment for coding, debugging, and goin 3 min read Building Calculator using PyQt5 in Python In this article we will see how we can create a calculator using PyQt5,A calculator is something used for making mathematical calculations, in particular a small electronic device with a keyboard and a visual display. below is the how the calculator will looks like GUI implementation steps Create a 5 min read Like