PyQt
Encyclopedia
PyQt is a Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

 binding
Language binding
In computing, a binding from a programming language to a library or OS service is an API providing that service in the language.Many software libraries are written in systems programming languages such as C or C++...

 of the cross-platform
Cross-platform
In computing, cross-platform, or multi-platform, is an attribute conferred to computer software or computing methods and concepts that are implemented and inter-operate on multiple computer platforms...

 GUI
Gui
Gui or guee is a generic term to refer to grilled dishes in Korean cuisine. These most commonly have meat or fish as their primary ingredient, but may in some cases also comprise grilled vegetables or other vegetarian ingredients. The term derives from the verb, "gupda" in Korean, which literally...

 toolkit Qt
Qt (toolkit)
Qt is a cross-platform application framework that is widely used for developing application software with a graphical user interface , and also used for developing non-GUI programs such as command-line tools and consoles for servers...

. It is one of the alternatives for GUI programming in Python to Tkinter
Tkinter
Tkinter is a Python binding to the Tk GUI toolkit. It is the standard Python interface to the Tk GUI toolkit and is Python's de-facto standard GUI, and is included with the standard Windows install of Python....

, which is bundled with Python. Other popular alternatives are PySide
PySide
PySide 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 PyGTK, PyQt and wxPython. Like Qt, PySide is free software...

, PyGTK
PyGTK
PyGTK is a set of Python wrappers for the GTK+ graphical user interface library. PyGTK is free software and licensed under the LGPL. It is analogous to PyQt and wxPython which are python wrappers for Qt and wxWidgets respectively. Its original author is the prominent GNOME developer James Henstridge...

, and wxPython
WxPython
-External links:* * at showmedo...

. Like Qt, PyQt is free software
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

. PyQt is implemented as a Python plug-in.

PyQt is developed by the British
United Kingdom
The United Kingdom of Great Britain and Northern IrelandIn the United Kingdom and Dependencies, other languages have been officially recognised as legitimate autochthonous languages under the European Charter for Regional or Minority Languages...

 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
GNU General Public License
The GNU General Public License is the most widely used free software license, originally written by Richard Stallman for the GNU Project....

 (GPL) and commercial license, but not the GNU Lesser General Public License
GNU Lesser General Public License
The GNU Lesser General Public License or LGPL is a free software license published by the Free Software Foundation . It was designed as a compromise between the strong-copyleft GNU General Public License or GPL and permissive licenses such as the BSD licenses and the MIT License...

 (LGPL). PyQt supports Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...

 and other flavours of Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

, as well as Mac OS X
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...

 and Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

.

PyQt implements around 440 classes and over 6,000 functions and methods including:
  • a substantial set of GUI widgets
  • classes
    Class (computer science)
    In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...

     for accessing SQL
    SQL
    SQL is a programming language designed for managing data in relational database management systems ....

     database
    Database
    A database is an organized collection of data for one or more purposes, usually in digital form. The data are typically organized to model relevant aspects of reality , in a way that supports processes requiring this information...

    s (ODBC, MySQL
    MySQL
    MySQL officially, but also commonly "My Sequel") is a relational database management system that runs as a server providing multi-user access to a number of databases. It is named after developer Michael Widenius' daughter, My...

    , PostgreSQL
    PostgreSQL
    PostgreSQL, often simply Postgres, is an object-relational database management system available for many platforms including Linux, FreeBSD, Solaris, MS Windows and Mac OS X. It is released under the PostgreSQL License, which is an MIT-style license, and is thus free and open source software...

    , Oracle
    Oracle database
    The Oracle Database is an object-relational database management system produced and marketed by Oracle Corporation....

    )
  • QScintilla, Scintilla
    Scintilla (editing component)
    Scintilla is a free library that provides text-editing functions, with an emphasis on advanced features for source code editing. SciTE , Notepad++ and Notepad2 are standalone editors based on Scintilla.-Features:...

    -based rich text editor widget
  • data aware widgets that are automatically populated from a database
  • an XML
    XML
    Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

     parser
  • SVG support
  • classes for embedding ActiveX
    ActiveX
    ActiveX is a framework for defining reusable software components in a programming language-independent way. Software applications can then be composed from one or more of these components in order to provide their functionality....

     controls on Windows (only in commercial version)


To automatically generate these bindings, Phil Thompson developed the tool SIP
SIP (software)
SIP is an open source software tool used to connect computer programs or libraries written in C or C++ with the scripting language Python. It is a concurrent of SWIG....

, which is also used in other projects.

In August 2009, Nokia
Nokia
Nokia Corporation is a Finnish multinational communications corporation that is headquartered in Keilaniemi, Espoo, a city neighbouring Finland's capital Helsinki...

, now the owners of the Qt toolkit, released PySide
PySide
PySide 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 PyGTK, PyQt and wxPython. Like Qt, PySide is free software...

, providing similar functionality, but under the LGPL
GNU Lesser General Public License
The GNU Lesser General Public License or LGPL is a free software license published by the Free Software Foundation . It was designed as a compromise between the strong-copyleft GNU General Public License or GPL and permissive licenses such as the BSD licenses and the MIT License...

, 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.
  • The QtCore module contains the core non-GUI classes, including the event loop and Qt's signal and slot mechanism. It also includes platform independent abstractions for Unicode
    Unicode
    Unicode is a computing industry standard for the consistent encoding, representation and handling of text expressed in most of the world's writing systems...

    , threads, mapped files, shared memory, regular expressions, and user and application settings.
  • The QtGui module contains the majority of the GUI classes. These include a number of table, tree and list classes based on the model-view-controller design pattern. Also provided is a sophisticated 2D
    2D computer graphics
    2D computer graphics is the computer-based generation of digital images—mostly from two-dimensional models and by techniques specific to them...

     canvas widget capable of storing thousands of items including ordinary widgets.
  • The QtNetwork module contains classes for writing UDP
    User Datagram Protocol
    The User Datagram Protocol is one of the core members of the Internet Protocol Suite, the set of network protocols used for the Internet. With UDP, computer applications can send messages, in this case referred to as datagrams, to other hosts on an Internet Protocol network without requiring...

     and TCP
    Transmission Control Protocol
    The Transmission Control Protocol is one of the core protocols of the Internet Protocol Suite. TCP is one of the two original components of the suite, complementing the Internet Protocol , and therefore the entire suite is commonly referred to as TCP/IP...

     clients and servers. It includes classes that implement FTP and HTTP clients and support DNS
    Domain name system
    The Domain Name System is a hierarchical distributed naming system for computers, services, or any resource connected to the Internet or a private network. It associates various information with domain names assigned to each of the participating entities...

     lookups. Network events are integrated with the event loop making it very easy to develop networked applications.
  • The QtOpenGL module contains classes that enable the use of OpenGL
    OpenGL
    OpenGL is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL...

     in rendering 3D
    3D computer graphics
    3D computer graphics are graphics that use a three-dimensional representation of geometric data that is stored in the computer for the purposes of performing calculations and rendering 2D images...

     graphics in PyQt applications.
  • The QtSql module contains classes that integrate with open-source and proprietary SQL databases. It includes editable data models for database tables that can be used with GUI classes. It also includes an implementation of SQLite
    SQLite
    SQLite is an ACID-compliant embedded relational database management system contained in a relatively small C programming library. The source code for SQLite is in the public domain and implements most of the SQL standard...

    .
  • The QtSvg module contains classes for displaying the contents of SVG files. It supports the static features of SVG 1.2 Tiny.
  • The QtXml module implements SAX
    Simple API for XML
    SAX is an event-based sequential access parser API developed by the XML-DEV mailing list for XML documents. SAX provides a mechanism for reading data from an XML document that is an alternative to that provided by the Document Object Model...

     and DOM
    Document Object Model
    The Document Object Model is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents. Aspects of the DOM may be addressed and manipulated within the syntax of the programming language in use...

     interfaces to Qt's XML parser.
  • The QtMultimedia module implements low-level multimedia functionality. Application developers would normally use the phonon
    Phonon (KDE)
    Phonon is the multimedia API provided by Qt and is the standard abstraction for handling multimedia streams within the KDE Software Compilation 4....

     module.
  • The QtDesigner module contains classes that allow Qt Designer to be extended using PyQt.
  • The Qt module consolidates the classes contained in all of the modules described above into a single module. This has the advantage that you don't have to worry about which underlying module contains a particular class. It has the disadvantage that it loads the whole of the Qt framework, thereby increasing the memory footprint of an application. Whether you use this consolidated module, or the individual component modules is down to personal taste.
  • The uic module implements support for handling the XML files created by Qt Designer that describe the whole or part of a graphical user interface. It includes classes that load an XML file and render it directly, and classes that generate Python code from an XML file for later execution.

Hello world example

The below code shows a small window on the screen.

  1. ! /usr/bin/env python
  2. -*- coding: 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 *
  1. Every PyQt4 application must create an application object.
  2. The application object is located in the QtGui module.

a = QApplication(sys.argv)
  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.

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

  • Anki
    Anki
    Anki is a spaced repetition flashcard program. The software is similar to SuperMemo, a commercial product for the same purpose, and Mnemosyne, another free flashcard program. Anki is the Japanese word for "memorizing"....

    , a spaced repetition flashcard program
  • Eric Python IDE
    Eric Python IDE
    Eric is a free integrated development environment for the Python and Ruby programming languages. Eric4 is the variant for Python 2 and eric5 is the one for Python 3....

  • Kodos
    Kodos Python Regular Expression Debugger
    Kodos is a FLOSS regular expression debugger written in Python, developed by Phil Schwartz. Because Python conforms to the Perl Compatible Regular Expressions standard for its regular expressions, Kodos can be used for debugging regular expressions for any other language that conforms.-External...

    , Python Regular Expression Debugger
  • Orange
    Orange (software)
    Orange is a component-based data mining and machine learning software suite, featuring friendly yet powerful and flexible visual programming front-end for explorative data analysis and visualization, and Python bindings and libraries for scripting...

    , a data mining and visualization framework
  • qt-recordMyDesktop
    RecordMyDesktop
    RecordMyDesktop is a free and open source desktop screencasting software application written for GNU/Linux. The program is separated into two parts; a command line tool that performs the tasks of capturing and encoding, and an interface that exposes the program functionality graphically...

    , Qt4 frontend for recordMyDesktop
  • Quantum GIS
    Quantum GIS
    Quantum GIS is a free software desktop Geographic Information Systems application that provides data viewing, editing, and analysis capabilities.-Development:...

    , a free software desktop Geographic Information Systems (GIS) application
  • Veusz
    Veusz
    Veusz is a scientific plotting package. Veusz is a Qt application written in Python, PyQt and NumPy. It is freely available for anyone to distribute under the terms of the GPL. It is designed to produce publication-quality plots. The name should be pronounced as "views".This program produces...

    , a scientific plotting application
  • Spyder, a lightweight Python IDE

See also

  • pythonqt
  • PySide
    PySide
    PySide 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 PyGTK, PyQt and wxPython. Like Qt, PySide is free software...

  • PyGTK
    PyGTK
    PyGTK is a set of Python wrappers for the GTK+ graphical user interface library. PyGTK is free software and licensed under the LGPL. It is analogous to PyQt and wxPython which are python wrappers for Qt and wxWidgets respectively. Its original author is the prominent GNOME developer James Henstridge...

  • wxPython
    WxPython
    -External links:* * at showmedo...

  • Tkinter
    Tkinter
    Tkinter is a Python binding to the Tk GUI toolkit. It is the standard Python interface to the Tk GUI toolkit and is Python's de-facto standard GUI, and is included with the standard Windows install of Python....


External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK