

{"id":23226,"date":"2018-07-31T04:00:40","date_gmt":"2018-07-30T22:30:40","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=23226"},"modified":"2026-04-25T12:13:36","modified_gmt":"2026-04-25T06:43:36","slug":"python-pyqt5-tutorial","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-pyqt5-tutorial\/","title":{"rendered":"Python PyQt5 Tutorial &#8211; Example and Applications"},"content":{"rendered":"<p><span style=\"font-weight: 400\">Today, we will explore Python PyQt5 Tutorial. In this PyQt5 tutorial of Python, we will learn a Python binding of Qt, which is a cross-platform <em>GUI toolkit<\/em>. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Moreover, we will see how to plot various GUI elements like buttons, windows, and input dialogs. <\/span><\/p>\n<p><span style=\"font-weight: 400\">We will talk about version PyQt5, which isn\u2019t backwards-compatible with version PyQt4. Also, we will look at PyQt Applications.<\/span><\/p>\n<h3>What is PyQt5?<\/h3>\n<p><span style=\"font-weight: 400\">PyQt is a Python binding of Qt, a cross-platform GUI toolkit. <\/span><\/p>\n<p><span style=\"font-weight: 400\">This is free software by Riverbank Computing and implements over 440 classes and more than 6000 functions and methods. <\/span><\/p>\n<p><strong>Some of these are:<\/strong><\/p>\n<div id=\"attachment_23243\" style=\"width: 154px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/pyqt5.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23243\" class=\"wp-image-23243 size-thumbnail\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/pyqt5-144x150.png\" alt=\"PyQt5 Tutorial\" width=\"144\" height=\"150\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/pyqt5-144x150.png 144w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/pyqt5-288x300.png 288w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/pyqt5-768x801.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/pyqt5-982x1024.png 982w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/pyqt5.png 1200w\" sizes=\"auto, (max-width: 144px) 100vw, 144px\" \/><\/a><p id=\"caption-attachment-23243\" class=\"wp-caption-text\">PyQt5 Tutorial &#8211; What is PyQt5<\/p><\/div>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">A set of GUI widgets.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">An XML parser.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">QScintilla, a rich-text editor widget based on Scintilla.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">SVG support.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Data-aware widgets.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Classes to access SQL databases.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Classes to embed ActiveX controls on Windows.<\/span><\/li>\n<\/ul>\n<p><strong>Features of PyQt5:<\/strong><\/p>\n<ul>\n<li><strong>Cross &#8211; platform compatibility:<\/strong> It can be used to develop applications on various operating systems like Windows, Linux, macOS.<\/li>\n<li><strong>Customisable widgets:<\/strong> It provides you with a wide range of personalised tools that can be used to create a GUI for many applications.<\/li>\n<li><strong>Advanced graphics:<\/strong> It supports advanced graphics creation, like 2D and 3D animations that can be used to create data visualizations.<\/li>\n<li><strong>Event-driven programming:<\/strong> It allows developers to react to the user&#8217;s input and the system events.<\/li>\n<\/ul>\n<h4>1. Modules in PyQt5<\/h4>\n<p><strong>We have the following modules available in PyQt5:<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">QtQml<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">QtQtuick<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">QtCore<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">QtGui<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">QtPrintSupport<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">GUI toolkit QtWidgets<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">QGLContext<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">QGLFormat<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">QGLWidget<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">QtWidget<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">QtWebKit<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">QtWebKitWidgets<\/span><\/li>\n<\/ul>\n<h4>2. PyQt5 Installation<\/h4>\n<p><span style=\"font-weight: 400\">For this, you need to install PyQt5. You can use pip for this-<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">pip install pyqt5<\/pre>\n<p><span style=\"font-weight: 400\">To import it into IDLE, you can do the following-<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import PyQt5<\/pre>\n<h3>How to Create a Window in Python PyQt5?<\/h3>\n<p><span style=\"font-weight: 400\">Let\u2019s take a simple example of PyQt5 in Python to create an empty window on our screen.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import sys\r\n&gt;&gt;&gt; from PyQt5.QtWidgets import QApplication, QWidget\r\n&gt;&gt;&gt; app=QApplication(sys.argv)\r\n&gt;&gt;&gt; root=QWidget()\r\n&gt;&gt;&gt; root.resize(320,240)\r\n&gt;&gt;&gt; root.setWindowTitle('Hello, world!')\r\n&gt;&gt;&gt; root.show()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div id=\"attachment_23246\" style=\"width: 347px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/window1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23246\" class=\"wp-image-23246 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/window1.png\" alt=\"PyQt5 Tutorial\" width=\"337\" height=\"277\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/window1.png 337w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/window1-150x123.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/window1-300x247.png 300w\" sizes=\"auto, (max-width: 337px) 100vw, 337px\" \/><\/a><p id=\"caption-attachment-23246\" class=\"wp-caption-text\">Creating a Window in Python<\/p><\/div>\n<p><span style=\"font-weight: 400\">To enter the main loop for the application, we do the following-<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">sys.exit(app.exec_())<\/pre>\n<p><span style=\"font-weight: 400\">Another way to create a window will be:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import sys\r\n&gt;&gt;&gt; from PyQt5.QtWidgets import QApplication, QWidget\r\n&gt;&gt;&gt; from PyQt5.QtGui import QIcon\r\n&gt;&gt;&gt; class App(QWidget):\r\n      def __init__(self):\r\n              super().__init__()\r\n              self.title='Hello, world!'\r\n              self.left=10\r\n              self.top=10\r\n              self.width=640\r\n              self.height=480\r\n              self.initUI()\r\n      def initUI(self):\r\n              self.setWindowTitle(self.title)\r\n              self.setGeometry(self.left,self.top,self.width,self.height)\r\n              self.show()\r\n&gt;&gt;&gt; if __name__=='__main__':\r\n        app=QApplication(sys.argv)\r\n        ex=App()\r\n        sys.exit(app.exec_())<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div id=\"attachment_23247\" style=\"width: 506px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/window2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23247\" class=\"wp-image-23247 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/window2.png\" alt=\"PyQt5 Tutorial\" width=\"496\" height=\"370\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/window2.png 496w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/window2-150x112.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/window2-300x224.png 300w\" sizes=\"auto, (max-width: 496px) 100vw, 496px\" \/><\/a><p id=\"caption-attachment-23247\" class=\"wp-caption-text\">Creating a Window in Python<\/p><\/div>\n<h3>Adding a Status Bar to Python PyQt5<\/h3>\n<p><span style=\"font-weight: 400\">It is possible to add a status bar to our window.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import sys\r\n&gt;&gt;&gt; from PyQt5.QtWidgets import QApplication,QWidget,QMainWindow #Imported one more module\r\n&gt;&gt;&gt; from PyQt5.QtGui import QIcon\r\n&gt;&gt;&gt; class App(QMainWindow):\r\n       def __init__(self):\r\n              super().__init__()\r\n              self.title='Hello, world!'\r\n              self.left=10\r\n              self.top=10\r\n              self.width=640\r\n              self.height=480\r\n              self.initUI()\r\ndef initUI(self):\r\n              self.setWindowTitle(self.title)\r\n              self.setGeometry(self.left,self.top,self.width,self.height)\r\n              self.statusBar().showMessage('In progress') #Added\r\n              self.show()\r\n&gt;&gt;&gt; if __name__=='__main__':\r\n       app=QApplication(sys.argv)\r\n       ex=App()<\/pre>\n<p><span style=\"font-weight: 400\">We add this to the main window, and the showMessage() method prints it out to it.<\/span><\/p>\n<p><strong>Output<\/strong><\/p>\n<div id=\"attachment_23248\" style=\"width: 666px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/status-bar.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23248\" class=\"wp-image-23248 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/status-bar.png\" alt=\"PyQt5 Tutorial\" width=\"656\" height=\"518\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/status-bar.png 656w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/status-bar-150x118.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/status-bar-300x237.png 300w\" sizes=\"auto, (max-width: 656px) 100vw, 656px\" \/><\/a><p id=\"caption-attachment-23248\" class=\"wp-caption-text\">Adding a Status Bar in Python<\/p><\/div>\n<h3>Adding Buttons to Python PyQt5<\/h3>\n<p><span style=\"font-weight: 400\">Using the QPushButton class, we can add buttons to our screen.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; from PyQt5.QtWidgets import QApplication,QWidget,QPushButton\r\n&gt;&gt;&gt; from PyQt5.QtCore import pyqtSlot\r\n&gt;&gt;&gt; import sys\r\n&gt;&gt;&gt; class App(QWidget):\r\n       def __init__(self):\r\n               super().__init__()\r\n               self.title='Hello, world!'\r\n               self.left=10\r\n               self.top=10\r\n               self.width=640\r\n               self.height=480\r\n               self.initUI()\r\n       def initUI(self):\r\n               self.setWindowTitle(self.title)\r\n               self.setGeometry(self.left,self.top,self.width,self.height)\r\n               button=QPushButton('Click me',self)\r\n               button.setToolTip('Thank you for thinking about me')\r\n               button.move(100,70)\r\n               self.show()\r\n&gt;&gt;&gt; if __name__=='__main__':\r\n       app=QApplication(sys.argv)\r\n       ex=App()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div id=\"attachment_23249\" style=\"width: 665px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/button.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23249\" class=\"wp-image-23249 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/button.png\" alt=\"PyQt5 Tutorial\" width=\"655\" height=\"516\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/button.png 655w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/button-150x118.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/button-300x236.png 300w\" sizes=\"auto, (max-width: 655px) 100vw, 655px\" \/><\/a><p id=\"caption-attachment-23249\" class=\"wp-caption-text\">Adding Buttons<\/p><\/div>\n<h3>Signals and Slots in PyQt5<\/h3>\n<p><span style=\"font-weight: 400\">On an event, like a user click, a PyQt5 widget can emit a signal. For a button click (a signal), we can specify an action (a slot).<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; from PyQt5.QtWidgets import *\r\n&gt;&gt;&gt; import sys\r\n&gt;&gt;&gt; class Dialog(QDialog):\r\n       def slot_method(self):\r\n               print(\"Calling the slot\")\r\n       def __init__(self):\r\n               super(Dialog,self).__init__()\r\n               button=QPushButton(\"Click me\")\r\n               button.clicked.connect(self.slot_method)\r\n               mainLayout=QVBoxLayout()\r\n               mainLayout.addWidget(button)\r\n               self.setLayout(mainLayout)\r\n               self.setWindowTitle(\"Hello, world!\")\r\n&gt;&gt;&gt; if __name__=='__main__':\r\n       app=QApplication(sys.argv)\r\n       dialog=Dialog()\r\n&gt;&gt;&gt; dialog.exec_()<\/pre>\n<p><strong>Calling the slot<\/strong><\/p>\n<div id=\"attachment_23250\" style=\"width: 382px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/signals-and-slots.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23250\" class=\"wp-image-23250 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/signals-and-slots.png\" alt=\"PyQt5 Tutorial\" width=\"372\" height=\"234\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/signals-and-slots.png 372w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/signals-and-slots-150x94.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/signals-and-slots-300x189.png 300w\" sizes=\"auto, (max-width: 372px) 100vw, 372px\" \/><\/a><p id=\"caption-attachment-23250\" class=\"wp-caption-text\">Signals and Slots<\/p><\/div>\n<h3>Message Boxes in PyQt5<\/h3>\n<p><span style=\"font-weight: 400\">Let\u2019s ask the user if he likes cookies<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; from PyQt5.QtWidgets import QApplication,QWidget,QPushButton,QMessageBox\r\n&gt;&gt;&gt; import sys\r\n&gt;&gt;&gt; from PyQt5.QtCore import pyqtSlot\r\n&gt;&gt;&gt; from PyQt5.QtGui import QIcon\r\n&gt;&gt;&gt; class App(QWidget):\r\n       def __init__(self):\r\n               super().__init__()\r\n               self.title='Hello, world!'\r\n               self.left=10\r\n               self.top=10\r\n               self.width=400\r\n               self.height=250\r\n               self.initUI()\r\n       def initUI(self):\r\n               self.setWindowTitle(self.title)\r\n               self.setGeometry(self.left,self.top,self.width,self.height)\r\n               buttonReply=QMessageBox.question(self, 'Hello', \"Do you like cookies?\", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)\r\n               if buttonReply==QMessageBox.Yes:\r\n                       print(\"Yeah\")\r\n               else: print(\"Nah\")\r\n               self.show()\r\n&gt;&gt;&gt; if __name__=='__main__':\r\n       app=QApplication(sys.argv)\r\n       ex=App()<\/pre>\n<div id=\"attachment_23251\" style=\"width: 241px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/message-box1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23251\" class=\"wp-image-23251 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/message-box1.png\" alt=\"PyQt5 Tutorial\" width=\"231\" height=\"168\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/message-box1.png 231w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/message-box1-150x109.png 150w\" sizes=\"auto, (max-width: 231px) 100vw, 231px\" \/><\/a><p id=\"caption-attachment-23251\" class=\"wp-caption-text\">Message Boxes<\/p><\/div>\n<p>When we click yes, it prints Yeah, closes this message box and then opens a new window.<\/p>\n<div id=\"attachment_23253\" style=\"width: 487px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/message-box2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23253\" class=\"wp-image-23253 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/message-box2.png\" alt=\"PyQt5 Tutorial\" width=\"477\" height=\"326\" \/><\/a><p id=\"caption-attachment-23253\" class=\"wp-caption-text\">Message Boxes in Python<\/p><\/div>\n<h3>Adding a Textbox in PyQt5<\/h3>\n<p><span style=\"font-weight: 400\">For this, we use the methods setText() and text(); the widget is QLineEdit.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; from PyQt5.QtWidgets import QMainWindow,QApplication,QWidget,QPushButton,QAction,QLineEdit,QMessageBox\r\n&gt;&gt;&gt; import sys\r\n&gt;&gt;&gt; from PyQt5.QtGui import QIcon\r\n&gt;&gt;&gt; from PyQt5.QtCore import pyqtSlot\r\n&gt;&gt;&gt; class App(QMainWindow):\r\n       def __init__(self):\r\n               super().__init__()\r\n               self.title='Hello, world!'\r\n               self.left=10\r\n               self.top=10\r\n               self.width=400\r\n               self.height=140\r\n               self.initUI()\r\n       def initUI(self):\r\n               self.setWindowTitle(self.title)\r\n               self.setGeometry(self.left,self.top,self.width,self.height)\r\n               self.textbox=QLineEdit(self)\r\n               self.textbox.move(30,30)\r\n               self.textbox.resize(280,40)\r\n               self.button=QPushButton('Click me',self)\r\n               self.button.move(15,85)\r\n               self.button.clicked.connect(self.on_click)\r\n               self.show()\r\n       @pyqtSlot()\r\n       def on_click(self):\r\n               textboxValue=self.textbox.text()\r\n               QMessageBox.question(self, 'Hello, world!', \"Confirm: \"+textboxValue,                                                                            QMessageBox.Ok, QMessageBox.Ok)\r\n               self.textbox.setText(\"...\")\r\n&gt;&gt;&gt; if __name__=='__main__':\r\n       app=QApplication(sys.argv)\r\n       ex=App()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div id=\"attachment_23255\" style=\"width: 466px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/textbox.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23255\" class=\"wp-image-23255 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/textbox.png\" alt=\"PyQt5 Tutorial\" width=\"456\" height=\"220\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/textbox.png 456w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/textbox-150x72.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/textbox-300x145.png 300w\" sizes=\"auto, (max-width: 456px) 100vw, 456px\" \/><\/a><p id=\"caption-attachment-23255\" class=\"wp-caption-text\">Adding a Textbox<\/p><\/div>\n<div id=\"attachment_23256\" style=\"width: 430px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/textbox2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23256\" class=\"wp-image-23256 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/textbox2.png\" alt=\"PyQt5 Tutorial\" width=\"420\" height=\"180\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/textbox2.png 420w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/textbox2-150x64.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/textbox2-300x129.png 300w\" sizes=\"auto, (max-width: 420px) 100vw, 420px\" \/><\/a><p id=\"caption-attachment-23256\" class=\"wp-caption-text\">Adding a Textbox<\/p><\/div>\n<h3><span style=\"font-family: Georgia, Georgia, serif\">Creating a Menu in PyQt5<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Now, let\u2019s create a menu with headings <\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import sys\r\n&gt;&gt;&gt; from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QPushButton, QAction\r\n&gt;&gt;&gt; from PyQt5.QtGui import QIcon\r\n&gt;&gt;&gt; from PyQt5.QtCore import pyqtSlot\r\n&gt;&gt;&gt; class App(QMainWindow):\r\n       def __init__(self):\r\n               super().__init__()\r\n               self.title = 'Hello, world!\u2019'\r\n               self.left = 10\r\n               self.top = 10\r\n               self.width = 640\r\n               self.height = 400\r\n               self.initUI()\r\n       def initUI(self):\r\n               self.setWindowTitle(self.title)\r\n               self.setGeometry(self.left,self.top,self.width,self.height)\r\n               mainMenu=self.menuBar()\r\n               fileMenu=mainMenu.addMenu('File')\r\n               editMenu=mainMenu.addMenu('Edit')\r\n               viewMenu=mainMenu.addMenu('View')\r\n               searchMenu=mainMenu.addMenu('Search')\r\n               toolsMenu=mainMenu.addMenu('Tools')\r\n               helpMenu=mainMenu.addMenu('Help')\r\n               exitButton=QAction(QIcon('exit24.png'), 'Exit', self)\r\n               exitButton.setShortcut('Ctrl+Q')\r\n               exitButton.setStatusTip('Exit application')\r\n               exitButton.triggered.connect(self.close)\r\n               fileMenu.addAction(exitButton)\r\n               self.show()\r\n&gt;&gt;&gt; if __name__=='__main__':\r\n       app=QApplication(sys.argv)\r\n       ex=App()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div id=\"attachment_23257\" style=\"width: 666px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/menu.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23257\" class=\"wp-image-23257 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/menu.png\" alt=\"PyQt5 Tutorial\" width=\"656\" height=\"437\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/menu.png 656w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/menu-150x100.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/menu-300x200.png 300w\" sizes=\"auto, (max-width: 656px) 100vw, 656px\" \/><\/a><p id=\"caption-attachment-23257\" class=\"wp-caption-text\">Creating a Menu<\/p><\/div>\n<h3>Setting Absolute Position in PyQt5<\/h3>\n<p><span style=\"font-weight: 400\">You can put your widgets anywhere you want on the screen.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import sys\r\n&gt;&gt;&gt; from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QLabel\r\n&gt;&gt;&gt; from PyQt5.QtGui import QIcon\r\n&gt;&gt;&gt; class App(QMainWindow):\r\n       def __init__(self):\r\n               super().__init__()\r\n               self.title = 'Hello, world!'\r\n               self.left = 10\r\n               self.top = 10\r\n               self.width = 440\r\n               self.height = 280\r\n               self.initUI()\r\n       def initUI(self):\r\n               self.setWindowTitle(self.title)\r\n               self.setGeometry(self.left, self.top, self.width, self.height)\r\n               label = QLabel('Pink',self)\r\n               label.move(50,50)\r\n               label2 = QLabel('Blue',self)\r\n               label2.move(100,100)\r\n               label3 = QLabel('Green',self)\r\n               label3.move(150,150)\r\n               label4 = QLabel('Lavender',self)\r\n               label4.move(200,200)\r\nself.show()\r\n&gt;&gt;&gt; if __name__=='__main__':\r\n       app=QApplication(sys.argv)\r\n       ex=App()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div id=\"attachment_23258\" style=\"width: 466px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/positioning.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23258\" class=\"wp-image-23258 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/positioning.png\" alt=\"PyQt5 Tutorial\" width=\"456\" height=\"318\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/positioning.png 456w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/positioning-150x105.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/positioning-300x209.png 300w\" sizes=\"auto, (max-width: 456px) 100vw, 456px\" \/><\/a><p id=\"caption-attachment-23258\" class=\"wp-caption-text\">Setting Absolute Position<\/p><\/div>\n<h3>Creating Input Dialogs in PyQt5<\/h3>\n<p><span style=\"font-weight: 400\">It is possible to add an input dialog.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import sys\r\n&gt;&gt;&gt; from PyQt5.QtWidgets import QApplication,QWidget,QInputDialog,QLineEdit\r\n&gt;&gt;&gt; from PyQt5.QtGui import QIcon\r\n&gt;&gt;&gt; class App(QWidget):\r\n       def __init__(self):\r\n               super().__init__()\r\n               self.title='Hello, world!'\r\n               self.left=10\r\n               self.top=10\r\n               self.width=300\r\n               self.height=250\r\n               self.initUI()\r\n       def initUI(self):\r\n               self.setWindowTitle(self.title)\r\n               self.setGeometry(self.left,self.top,self.width,self.height)\r\n               self.getDouble()\r\n               self.show()\r\n       def getDouble(self):\r\n               d,okPressed=QInputDialog.getDouble(self,'Get double','Value',9,0.5,100,9.5)\r\n               if okPressed:\r\n                       print(d)\r\n&gt;&gt;&gt; if __name__=='__main__':\r\n       app=QApplication(sys.argv)\r\n       ex=App()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div id=\"attachment_23259\" style=\"width: 230px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/input-dialog.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23259\" class=\"wp-image-23259 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/input-dialog.png\" alt=\"PyQt5 Tutorial\" width=\"220\" height=\"134\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/input-dialog.png 220w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/input-dialog-150x91.png 150w\" sizes=\"auto, (max-width: 220px) 100vw, 220px\" \/><\/a><p id=\"caption-attachment-23259\" class=\"wp-caption-text\">Creating Input Dialogs<\/p><\/div>\n<h3>Loading Images to PyQt5<\/h3>\n<p><span style=\"font-weight: 400\">To load an image into your window, you can try the following-<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import sys\r\n&gt;&gt;&gt; from PyQt5.QtWidgets import QApplication,QWidget,QLabel\r\n&gt;&gt;&gt; from PyQt5.QtGui import QIcon,QPixmap\r\n&gt;&gt;&gt; import os\r\n&gt;&gt;&gt; os.chdir('C:\\\\Users\\\\Ram\\\\Desktop')\r\n&gt;&gt;&gt; class App(QWidget):\r\n       def __init__(self):\r\n               super().__init__()\r\n               self.title='Hello, world!'\r\n               self.left=10\r\n               self.top=10\r\n               self.width=640\r\n               self.height=480\r\n               self.initUI()\r\n       def initUI(self):\r\n               self.setWindowTitle(self.title)\r\n               self.setGeometry(self.left,self.top,self.width,self.height)\r\n               label=QLabel(self)\r\n               pixmap=QPixmap('df.png')\r\n               label.setPixmap(pixmap)\r\n               self.resize(pixmap.width(),pixmap.height())\r\n               self.show()\r\n&gt;&gt;&gt; if __name__=='__main__':\r\n       app=QApplication(sys.argv)\r\n       ex=App()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div id=\"attachment_23260\" style=\"width: 248px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/image-1-12.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23260\" class=\"wp-image-23260 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/image-1-12.png\" alt=\"PyQt5 Tutorial\" width=\"238\" height=\"138\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/image-1-12.png 238w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/image-1-12-150x87.png 150w\" sizes=\"auto, (max-width: 238px) 100vw, 238px\" \/><\/a><p id=\"caption-attachment-23260\" class=\"wp-caption-text\">Loading Images<\/p><\/div>\n<h3>Color Dialogs in PyQt5<\/h3>\n<p><span style=\"font-weight: 400\">A color dialog is one that lets you choose a color from a color picker.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import sys\r\n&gt;&gt;&gt; from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QColorDialog\r\n&gt;&gt;&gt; from PyQt5.QtGui import QIcon\r\n&gt;&gt;&gt; from PyQt5.QtCore import pyqtSlot\r\n&gt;&gt;&gt; from PyQt5.QtGui import QColor\r\n&gt;&gt;&gt; class App(QWidget):\r\n       def __init__(self):\r\n              super().__init__()\r\n              self.title='Hello, world!'\r\n              self.left=10\r\n              self.top=10\r\n              self.width=320\r\n              self.height=200\r\n              self.initUI()\r\n       def initUI(self):\r\n              self.setWindowTitle(self.title)\r\n              self.setGeometry(self.left,self.top,self.width,self.height)\r\n              button=QPushButton('Open color dialog', self)\r\n              button.setToolTip('This opens the color dialog')\r\n              button.move(10,10)\r\n              button.clicked.connect(self.on_click)\r\n              self.show()\r\n       @pyqtSlot()\r\n       def on_click(self):\r\n              openColorDialog(self)\r\n&gt;&gt;&gt; def openColorDialog(self):\r\n       color=QColorDialog.getColor()\r\n       if color.isValid():\r\n              print(color.name())\r\n&gt;&gt;&gt; if __name__=='__main__':\r\n       app=QApplication(sys.argv)\r\n       ex=App()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div id=\"attachment_23261\" style=\"width: 346px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/color-dialog.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23261\" class=\"wp-image-23261 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/color-dialog.png\" alt=\"PyQt5 Tutorial\" width=\"336\" height=\"238\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/color-dialog.png 336w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/color-dialog-150x106.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/color-dialog-300x213.png 300w\" sizes=\"auto, (max-width: 336px) 100vw, 336px\" \/><\/a><p id=\"caption-attachment-23261\" class=\"wp-caption-text\">Color Dialogs<\/p><\/div>\n<div id=\"attachment_23262\" style=\"width: 548px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/color-dialog2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23262\" class=\"wp-image-23262 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/color-dialog2.png\" alt=\"PyQt5 Tutorial\" width=\"538\" height=\"430\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/color-dialog2.png 538w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/color-dialog2-150x120.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/color-dialog2-300x240.png 300w\" sizes=\"auto, (max-width: 538px) 100vw, 538px\" \/><\/a><p id=\"caption-attachment-23262\" class=\"wp-caption-text\">Color Dialogs<\/p><\/div>\n<p>And then when we pick a color and click on \u2018OK\u2019, it gives us the HTML code of that color.<\/p>\n<div id=\"attachment_23263\" style=\"width: 147px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/color-dialog-3.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23263\" class=\"wp-image-23263 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/color-dialog-3.png\" alt=\"PyQt5 Tutorial\" width=\"137\" height=\"50\" \/><\/a><p id=\"caption-attachment-23263\" class=\"wp-caption-text\">Color Dialogs<\/p><\/div>\n<h3>Font Dialogs to PyQt5<\/h3>\n<p><span style=\"font-weight: 400\">Now to choose a font-<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; import sys\r\n&gt;&gt;&gt; from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QFontDialog\r\n&gt;&gt;&gt; from PyQt5.QtGui import QIcon\r\n&gt;&gt;&gt; from PyQt5.QtCore import pyqtSlot\r\n&gt;&gt;&gt; class App(QWidget):\r\n       def __init__(self):\r\n               super().__init__()\r\n               self.title='Hello, world!'\r\n               self.left=10\r\n               self.top=10\r\n               self.width=320\r\n               self.height=200\r\n               self.initUI()\r\n       def initUI(self):\r\n               self.setWindowTitle(self.title)\r\n               self.setGeometry(self.left,self.top,self.width,self.height)\r\n               button=QPushButton('The font dialog', self)\r\n               button.setToolTip('Opens the font dialog')\r\n               button.move(50,50)\r\n               button.clicked.connect(self.on_click)\r\n               self.show()\r\n       @pyqtSlot()\r\n       def on_click(self):\r\n               print('Click')\r\n               openFontDialog(self)\r\n&gt;&gt;&gt; def openFontDialog(self):\r\n       font,ok=QFontDialog.getFont()\r\n       if ok:\r\nprint(font.toString())\r\n&gt;&gt;&gt; if __name__=='__main__':\r\n       app=QApplication(sys.argv)\r\n       ex=App()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div id=\"attachment_23264\" style=\"width: 346px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font-dialog-1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23264\" class=\"wp-image-23264 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font-dialog-1.png\" alt=\"Python PyQt5\" width=\"336\" height=\"239\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font-dialog-1.png 336w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font-dialog-1-150x107.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font-dialog-1-300x213.png 300w\" sizes=\"auto, (max-width: 336px) 100vw, 336px\" \/><\/a><p id=\"caption-attachment-23264\" class=\"wp-caption-text\"><span style=\"font-weight: 400\">PyQt5 Tutorial &#8211;\u00a0<\/span>Font Dialogs<\/p><\/div>\n<div id=\"attachment_23265\" style=\"width: 526px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font-dialog-2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23265\" class=\"wp-image-23265 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font-dialog-2.png\" alt=\"PyQt5 tutorial\" width=\"516\" height=\"398\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font-dialog-2.png 516w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font-dialog-2-150x116.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font-dialog-2-300x231.png 300w\" sizes=\"auto, (max-width: 516px) 100vw, 516px\" \/><\/a><p id=\"caption-attachment-23265\" class=\"wp-caption-text\"><span style=\"font-weight: 400\">\u00a0<\/span>Font Dialogs<\/p><\/div>\n<div id=\"attachment_23266\" style=\"width: 361px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font-dialog-3.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-23266\" class=\"wp-image-23266 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font-dialog-3.png\" alt=\"PyQt5 tutorial\" width=\"351\" height=\"52\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font-dialog-3.png 351w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font-dialog-3-150x22.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/font-dialog-3-300x44.png 300w\" sizes=\"auto, (max-width: 351px) 100vw, 351px\" \/><\/a><p id=\"caption-attachment-23266\" class=\"wp-caption-text\">Font Dialogs<\/p><\/div>\n<h3>Python PyQt Applications<\/h3>\n<p><span style=\"font-weight: 400\">Here\u2019s a list of applications that make use of PyQt-<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>Dropbox-<\/strong> File-hosting service.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>Spyder-<\/strong> Python IDE.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>Calibre-<\/strong> e-book management application.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>Leo-<\/strong> Outliner and literate programming editor.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>OpenShot-<\/strong> Video-editing program.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>Veusz-<\/strong> Scientific plotting application.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>Orange-<\/strong> Data-mining and visualization framework.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>Kodos-<\/strong> Regular-expression debugger.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Eric Python IDE.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>Anki-<\/strong> Spaced repetition flashcard program.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>Ninja-<\/strong>IDE- Extensible open-source Python IDE.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>qt-recordMyDesktop-<\/strong> Qt4 frontend for recordMyDesktop.<\/span><\/li>\n<\/ul>\n<p>So, this was all about PyQt5 Tutorial. Hope you like our explanation.<\/p>\n<h3>Python Interview Questions on PyQt5<\/h3>\n<p>1. What is PyQt5 in Python?<\/p>\n<p>2. What is PyQt5 used for in Python?<\/p>\n<p>3. What is the difference between PyQt4 and PyQt5?<\/p>\n<p>4. How to run PyQt5 on Windows?<\/p>\n<p>5. What are the benefits of using PyQt5 in Python?<\/p>\n<h3><span style=\"font-weight: 400\">Conclusion<\/span><\/h3>\n<p>PyQt 5\/6 wraps the Qt framework, giving you drag-and-drop design plus native-looking widgets on Windows, macOS, and Linux. Build main windows, dock panels, and signals-and-slots connections in minutes. Bundle apps with PyInstaller to ship one-click executables. Because PyQt ties into C++ Qt, performance stays high even for data-heavy dashboards.<\/p>\n<p><span style=\"font-weight: 400\">Hence, in this Python PyQt5 Tutorial, we saw how to create GUI elements with PyQt5. Once you get the syntax, it seems easy to work with PyQt5.\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, we will explore Python PyQt5 Tutorial. In this PyQt5 tutorial of Python, we will learn a Python binding of Qt, which is a cross-platform GUI toolkit. Moreover, we will see how to plot&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":23278,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[10277,10278,10280,10281,10282,10575,10777,10778,10780],"class_list":["post-23226","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-pyqt5-examples-and-demos","tag-pyqt5-installation","tag-pyqt5-modules","tag-pyqt5-tutorial","tag-pyqt5-tutorial-python-3","tag-python-gui-toolkit","tag-python-pyqt-tutorial","tag-python-pyqt5-tutorial","tag-python-qt5-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python PyQt5 Tutorial - Example and Applications - DataFlair<\/title>\n<meta name=\"description\" content=\"Python PyQt5 Tutorial,what is PyQt5,GUI toolkit,PyQt5 Example,PyQt5 modules,PyQt5 Installation,PyQt5 in Python,how to plot various GUI elements\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-pyqt5-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python PyQt5 Tutorial - Example and Applications - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Python PyQt5 Tutorial,what is PyQt5,GUI toolkit,PyQt5 Example,PyQt5 modules,PyQt5 Installation,PyQt5 in Python,how to plot various GUI elements\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-pyqt5-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-07-30T22:30:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-25T06:43:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-PyQt5-Tutorial-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python PyQt5 Tutorial - Example and Applications - DataFlair","description":"Python PyQt5 Tutorial,what is PyQt5,GUI toolkit,PyQt5 Example,PyQt5 modules,PyQt5 Installation,PyQt5 in Python,how to plot various GUI elements","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-pyqt5-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Python PyQt5 Tutorial - Example and Applications - DataFlair","og_description":"Python PyQt5 Tutorial,what is PyQt5,GUI toolkit,PyQt5 Example,PyQt5 modules,PyQt5 Installation,PyQt5 in Python,how to plot various GUI elements","og_url":"https:\/\/data-flair.training\/blogs\/python-pyqt5-tutorial\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-07-30T22:30:40+00:00","article_modified_time":"2026-04-25T06:43:36+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-PyQt5-Tutorial-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-pyqt5-tutorial\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-pyqt5-tutorial\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Python PyQt5 Tutorial &#8211; Example and Applications","datePublished":"2018-07-30T22:30:40+00:00","dateModified":"2026-04-25T06:43:36+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-pyqt5-tutorial\/"},"wordCount":960,"commentCount":6,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-pyqt5-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-PyQt5-Tutorial-01.jpg","keywords":["pyqt5 examples and demos","PyQt5 Installation","PyQt5 Modules","pyqt5 tutorial","pyqt5 tutorial python 3","Python GUI toolkit","python pyqt tutorial","Python PyQt5 Tutorial","python qt5 tutorial"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-pyqt5-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-pyqt5-tutorial\/","url":"https:\/\/data-flair.training\/blogs\/python-pyqt5-tutorial\/","name":"Python PyQt5 Tutorial - Example and Applications - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-pyqt5-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-pyqt5-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-PyQt5-Tutorial-01.jpg","datePublished":"2018-07-30T22:30:40+00:00","dateModified":"2026-04-25T06:43:36+00:00","description":"Python PyQt5 Tutorial,what is PyQt5,GUI toolkit,PyQt5 Example,PyQt5 modules,PyQt5 Installation,PyQt5 in Python,how to plot various GUI elements","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-pyqt5-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-pyqt5-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-pyqt5-tutorial\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-PyQt5-Tutorial-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/07\/Python-PyQt5-Tutorial-01.jpg","width":1200,"height":628,"caption":"Python PyQt5 Tutorial - Example and Applications"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-pyqt5-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python PyQt5 Tutorial &#8211; Example and Applications"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/23226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=23226"}],"version-history":[{"count":14,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/23226\/revisions"}],"predecessor-version":[{"id":147881,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/23226\/revisions\/147881"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/23278"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=23226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=23226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=23226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}