Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22851

Real Python: Python and PyQt: Building a GUI Desktop Calculator

$
0
0

Even though web and mobile applications appear to have taken over the software development market, there’s still demand for traditional graphical user interface (GUI) desktop applications. If you’re interested in building these kinds of applications in Python, then you’ll find a wide variety of libraries to choose from. They include Tkinter, wxPython, PyQt, PySide, and a few others.

In this tutorial, you’ll learn the basics of building GUI desktop applications with Python and PyQt.

In this tutorial, you’ll learn how to:

  • Create graphical user interfaces with Python and PyQt
  • Connect the user’s events on the app’s GUI with the app’s logic
  • Organize a PyQt app using a proper project layout
  • Create a fully functional GUI application with PyQt

For this tutorial, you’ll create a calculator app with Python and PyQt. This short project will help you grasp the fundamentals and get you up and running with this GUI library.

You can download the source code for the project and all examples in this tutorial by clicking on the link below:

Download Code:Click here to download the code that you’ll use to build a calculator in Python with PyQt in this tutorial.

Getting to Know PyQt

PyQt is a Python binding for Qt, which is a set of C++ libraries and development tools providing platform-independent abstractions for graphical user interfaces (GUIs). Qt also provides tools for networking, threads, regular expressions, SQL databases, SVG, OpenGL, XML, and many other powerful features.

Developed by RiverBank Computing Ltd, PyQt’s latest editions are:

  1. PyQt5: An edition that’s built against Qt 5.x only
  2. PyQt6: An edition that’s built against Qt 6.x only

In this tutorial, you’ll use PyQt6, as this version is the future of the library. From now on, be sure to consider any mention of PyQt as a reference to PyQt6.

Note: If you want to dive deeper into the differences between these two versions of the library, then check out the PyQt6 documentation on the topic.

PyQt6 is based on Qt v6. Therefore, it provides classes and tools for GUI creation, XML handling, network communication, regular expressions, threads, SQL databases, web browsing, and other technologies available in Qt. PyQt6 implements binding for many Qt classes in a set of Python modules, which are organized in a top-level Python package called PyQt6. For PyQt6 to work, you need Python 3.6.1 or later.

PyQt6 is compatible with Windows, Unix, Linux, macOS, iOS, and Android. This is an attractive feature if you’re looking for a GUI framework to develop multiplatform applications that have a native look and feel on each platform.

PyQt6 is available under two licenses:

  1. The Riverbank Commercial License
  2. The General Public License (GPL), version 3

Your PyQt6 license must be compatible with your Qt license. If you use the GPL license, then your code must also use a GPL-compatible license. If you want to use PyQt6 to create commercial applications, then you need a commercial license for your installation.

Note: The Qt Company has developed and currently maintains its own Python binding for the Qt library. The Python library is called Qt for Python and is the official Qt for Python. Its Python package is called PySide.

PyQt and PySide are both built on top of Qt. Their APIs are quite similar because they reflect the Qt API. That’s why porting PyQt code to PySide can be as simple as updating some imports. If you learn one of them, then you’ll be able to work with the other with minimal effort. If you want to dive deeper into the differences between these two libraries, then you can check out PyQt6 vs PySide6.

If you need more information about PyQt6 licensing, then check out the license FAQs page on the project’s official documentation.

Installing PyQt

You have several options for installing PyQt on your system or development environment. The recommended option is to use to use binary wheels. Wheels are the standard way to install Python packages from the Python package index, PyPI.

In any case, you need to consider that wheels for PyQt6 are only available for Python 3.6.1 and later. There are wheels for Linux, macOS, and Windows (64-bit).

All of these wheels include copies of the corresponding Qt libraries, so you won’t need to install them separately.

Another installation option is to build PyQt from source. This can be a bit complicated, so you might want to avoid it if possible. If you really need to build from source, then check out what the library’s documentation recommends in those cases.

Read the full article at https://realpython.com/python-pyqt-gui-calculator/ »


[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]


Viewing all articles
Browse latest Browse all 22851

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>