PyQt

PyQt

Qt Designer
Developer(s) Riverbank Computing
Stable release 4.8.5 / August 2, 2011; 6 months ago (2011-08-02)
Written in C++/Python[1]
Operating system Cross-platform
License GNU GPL and commercial
Website riverbankcomputing.com

PyQt is a Python binding of the cross-platform GUI toolkit Qt. It is one of the alternatives for GUI programming in Python to Tkinter, which is bundled with Python. Other popular alternatives are PySide, PyGTK, and wxPython. Like Qt, PyQt is free software. PyQt is implemented as a Python plug-in.

PyQt is 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 (GPL) and commercial license, but not the GNU Lesser General Public License (LGPL).[2] PyQt supports Linux and other flavours of Unix, as well as Mac OS X and Microsoft Windows.[3]

PyQt implements around 440 classes and over 6,000 functions and methods[4] including:

To automatically generate these bindings, Phil Thompson developed the tool SIP, which is also used in other projects.

In August 2009, Nokia, now the owners of the Qt toolkit, released PySide, providing similar functionality, but under the LGPL,[6] after failing to reach an agreement with Riverbank Computing[7] to change its licensing terms to include LGPL as an alternative license.

Contents

PyQt main components

PyQt4 contains the following Python modules.

Hello world example

The below code shows a small window on the screen.

#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Here we provide the necessary imports.
# The basic GUI widgets are located in QtGui module. 
import sys
from PyQt4.QtGui import *
 
# Every PyQt4 application must create an application object.
# The application object is located in the QtGui module.
a = QApplication(sys.argv)
 
# The QWidget widget is the base class of all user interface objects in PyQt4.
# We provide the default constructor for QWidget. The default constructor has no parent.
# A widget with no parent is called a window. 
w = QWidget()
 
w.resize(320, 240)  # The resize() method resizes the widget.
w.setWindowTitle("Hello, World!")  # Here we set the title for our window.
w.show()  # The show() method displays the widget on the screen.
 
sys.exit(a.exec_())  # Finally, we enter the mainloop of the application.

Notable applications that use PyQt

See also

References

Further reading

External links