PyQt Tutorial for Beginners
Introduction to PYQT
It's a wrapper for QT framework developed by river bank computing ltd. It is a set of both v2 and v3 of the QT application framework. It has one of the most popular and powerful GUI (graphical user interface) library. QT developed itself as a part of the QT project. It has two versions.- Qt4- It is more straightforward, so we always prefer qt4. It can be used in python version 2 and version 3 both.
- Qt5-slightly newer comes with a lot more dependencies and also has slightly different in the licensing process. It can be used only in python version 3.
Required Platform
It can be run on various platforms like Windows, Unix, Linux, Mac OS x. The latest version of PYQT also comes with the acceptability of android and Ios. It is available for download on riverbank’s official website for all supported operating system. It can be downloaded for a verity of operating systems like Windows, Linux, and MacOS. The different file is available for different versions of the operating system.Components of PYQT-
Both versions of PYQT contains different components. PYQT 5 COMPONENT- It has various types of component these are installed in the python development package. It is described under the list of modules. It is distributed as several source packages and binaries for implementation one or more logically related module. It contains various components like- QT designer plugins
- Utility programs
PYQT4 Components
PYQT4 contains various numbers of components. Mostly there are several python extension modules. These are all installed in PYQT4 package.- The Qt core module- This module contains the core non-GUI classes and platform independent abstractions.
- The Qt GUI module-It contains GUI classes
- The Qt Help module-This module includes creating and viewing classes of the searchable module.
- The Qt Network module- This module contains UDP and TCP clients classes.
- The Qt Script module- this module contains classes for scripting.
- The Qt Open Gl module- this module is responsible for the use of GL in 3D graphics in PyQt4 applications.
- The Qt Script tool- This module is responsible for containing classes of additional component like a debugger.
- The Qt SQL module- This module is integrated with the SQL database.
- The Qt SVG module- This module displays the content of SVG files.
- The Qt Test module- This module contains the function that is responsible for unit testing of PyQt4 applications.
- The Qt Web Kit module- it implements a web browser engine.
What is PyQt used for?
QT is not all about GUI toolkit. It is more than a GUI kit. It brings together the QT C++ cross platforms application frameworks and the language python. The QT includes abstraction of network sockets, Unicode, databases, RE (regular expression), etc. it also includes a help system, a multimedia framework and a massive collection of GUI widgets. It also includes a graphical user interface designer called QT designer. In QT designer it is possible to generate a new GUI controls written in python code. PYQT can generate python code from Qt designer. Python is a simple and powerful language. It is an object-oriented language. Due to its simplicity, it is a popular language. PYQT makes it more powerful. PYQT binds all the advantages of QT and python together. It provides a programmer all the power of QT with python's simplicity. Steps required for creating a simple GUI application using PYQT-- Import module for GUI (QtGui)
- Create an object for the application
- The QWidget object creates a top-level window to add a Qlabel object under Qwidget.
- Set the caption of Label
- Apply method setGeometry for defining the size and the position.
- Apply method app.exec_() for the main loop.
Some basic imports
Import sys- we use import sys to make application accept the command line arguments and after we use for a clean exit. From PyQt4 import QtGui-Here, we import QtGui. This import deals with all the things between PyQt4 and QtGui. PyQt deals with other section also some of are as follows- QtCore-it deals with other non-GUI components QtNetworks-it manages the networking between components. QtOpenGl- it provides permission for the incorporation of open Gl. QtSql- deals with SQL database. QtSvg- supports for vector graphics. QtXml- it is for XML data handling. “HELLO” WORD PROGRAM-import sys from PyQt4.QtGui import * app = QApplication(sys.argv) button = QPushButton("Hello World", None) button.show()app.exec_()Output:
Hello World
Difference between PyQt and PySide
PyQt |
Tkinter |
PyQt comes only with a GPL license. | PySide is more permissive and is released under LGPL. |
PyQt supports python version 4 and 5. | PySide supports python 3 since 1.0.8. |
RIVERBANK COMPUTING LIMITED mainly develops it. | It is developed by NOKIA. |
For commercial projects PyQt requires fee for commercial license. | LGPL license of PySide permits commercial projects. |
Difference Between PyQt vs. Tkinter
PyQt |
Tkinter |
PyQt has a large library; it means it has more choice of widgets. | Tkinter has lesser library than PyQt it means no of widgets also be less than PyQt. |
It works on the signal slot system. | Tk works on call back system. |
Due to its massive library of the widget, it is suitable for the significant project. | It is better for minor projects. |