PyQt


PyQt is a Python binding of the cross-platform GUI toolkit Qt, implemented as a Python plug-in. PyQt is free software developed by the British firm Riverbank Computing. It is available under similar terms to Qt versions older than 4.5; this means a variety of licenses including GNU General Public License and commercial license, but not the GNU Lesser General Public License. PyQt supports Microsoft Windows as well as various flavours of UNIX, including Linux and MacOS.
PyQt implements around 440 classes and over 6,000 functions and methods including:
To automatically generate these bindings, Phil Thompson developed the tool SIP, which is also used in other projects.
In August 2009, Nokia, the then owners of the Qt toolkit, released PySide, providing similar functionality, but under the LGPL, after failing to reach an agreement with Riverbank Computing to change its licensing terms to include LGPL as an alternative license.

PyQt main components

PyQt4 contains the following Python modules.
PyQt5 contains the following Python modules:
PyQt version 4 works with both Qt 4 and Qt 5. PyQt version 5 only supports Qt version 5, and drops support for features that are deprecated in Qt 5.

Hello World example

The below code shows a small window on the screen.

PyQt4


  1. ! /usr/bin/env python3
  2. Character Encoding: UTF-8
  3. Here we provide the necessary imports.
  4. The basic GUI widgets are located in QtGui module.
import sys
from PyQt4.QtGui import QApplication, QWidget
  1. Every PyQt4 application must create an application object.
  2. The application object is located in the QtGui module.
app = QApplication
  1. The QWidget widget is the base class of all user interface objects in PyQt4.
  2. We provide the default constructor for QWidget. The default constructor has no parent.
  3. A widget with no parent is called a window.
root = QWidget
root.resize # The resize method resizes the widget.
root.setWindowTitle # Here we set the title for our window.
root.show # The show method displays the widget on the screen.
sys.exit) # Finally, we enter the mainloop of the application.

PyQt5


  1. ! /usr/bin/env python3
  2. Character Encoding: UTF-8
  3. Here we provide the necessary imports.
  4. The basic GUI widgets are located in QtWidgets module.
import sys
from PyQt5.QtWidgets import QApplication, QWidget
  1. Every PyQt5 application must create an application object.
  2. The application object is located in the QtWidgets module.
app = QApplication
  1. The QWidget widget is the base class of all user interface objects in PyQt5.
  2. We provide the default constructor for QWidget. The default constructor has no parent.
  3. A widget with no parent is called a window.
root = QWidget
root.resize # The resize method resizes the widget.
root.setWindowTitle # Here we set the title for our window.
root.show # The show method displays the widget on the screen.
sys.exit) # Finally, we enter the mainloop of the application.

Notable applications that use PyQt