PyQt52018 Latest Tutorial
This tutorial will teach you how to use PyQt5 to make a Python desktop appdesktop app. This tutorial covers everything - from the best way to configure PyQt to compiling your app and distributing it for others to use. You can use Windows, Mac or Linux systems. The prerequisite is that you need to have Python version 3.5+ installed first.
What is PyQt5?
PyQt is a third-party library for Python that enables you to use the Qt GUI framework, the QT graphical user interface framework. Qt itself is written using the C++ programming language. Using it in Python will allow you to build an application faster and without sacrificing the speed of C++.
PyQt5 refers to the latest version 5 of Qt. You may still see information about (Py)Qt4 from time to time, but this version is quite old and is no longer officially supported.
One of PyQt's interesting new competitors is Qt for Python. Their APIs are basically the same. Unlike PyQt, it uses the LGPLGNU Wide General Public License, which means it can be used for free in commercial projects. It's backed by Qt, so most likely it's the future. We use PyQt in this tutorial because it is more mature. Because these APIs are basically the same, you can easily move to Qt for Python afterwards.
The best way to manage dependencies in Python is through the virtual environmentvirtual environment. A virtual environment is really a local folder containing the library libraries needed for a particular project. The virtual environment's libraries are compared to the system's globally installed libraries, and the global libraries affect all your other projects.
To generate a virtual environment in the current folder, execute the following command.
This command will create a venv folder. To activate this virtual environment on a Windows system, run the following command.
On a Mac or Linux system, use the following command.
The virtual environment is successfully activated when you see a (venv) prefix on the command line.
Now we will install PyQt by executing the following command.
The reason we use version 5.9.2 is because not all (Py)Qt distributions are stable. And this version will guarantee no problems. Except for this nuance - congratulations! You have successfully installed PyQt5.
Create a graphical user interface
Let's start creating one of our GUI applications now! While the virtual environment is still active, start Python. We will execute the following command.