DEV Community

Cover image for How to install PyQt
amigos-maker
amigos-maker

Posted on • Updated on

How to install PyQt

PyQt is excellent for using for Python interfaces, as it is flexible, and allows you access to a wide array of functionalities.

But to get access to all its advantages, you must first install it correctly. Thus, let’s see down below how to install PyQt and get the best programming functionalities from this framework.

PyQt is a GUI framework for Python, it requires basic Python knowledge.

1 Setup

First of all, you will have to install Python, depending on your operating system. You can opt from distinct software, but the most popular ones are Windows and Linux.

Qt in Python comes in a package named PyQt. PyQt includes everything you need to start using GUIs in Qt Designer via Python.

On Linux (Ubuntu)

sudo apt-get install qtcreator pyqt5-dev-tools
sudo apt-get install python3-pyqt5
sudo apt-get install qttools5-dev-tools

For other platforms, use the website. You can download PyQt from their official page and opt for the Qt Designer package, too. Depending on your options, you will have to complete the installation process, as mentioned in the PyQt website.

2 Check the PyQt package you installed

As soon as the installation process is finished, you should be able to identify inside Python’s directory a folder named PyQt.

Here, you will discover library files for Python, along with executables and scripts.

The next step is to verify if Python has access to the PyQt package, and you can do so by opening a line in your command terminal.

$ python3
import PyQt5

You can also try a hello world script to see if PyQt works correctly.

3 Starting GUI in Python with PyQt

At this point, you will have to create a GUI and load it into Python (with designer).

/usr/bin/designer

After this, you will have to convert via PyQt, code in Python, and execute accordingly.

4 Creating custom settings to GUI events

After creating the interface, you will have to create a building software, or a part bridging GUI to the business approach.

Thus, you will need to design a Python script accordingly to the features you will want to have included in your finite product.

5 Setting up your GUI in Qt Designer

When you access Qt Designer, you should receive a dialog box prompting you to open a New Form. Opt for Dialog with Bottom or the default option and press the create button.

6 Creating buttons or widgets

In the Qt Designer window, you will find a setting named Widget Box. You can drag from there any type of widget you desire and adapt them depending on your project.

Keep in mind that the default functionality comes with two necessary buttons, OK and Cancel. Those can be modified by clicking on them and changing their settings in the Property Editor.

From this point on, you can mix and match a wide array of functionality related to Python and PyQt. It is a versatile method of coding, as it allows you to use several characteristics available with this framework.

qt designer

You can use this cross-platform on Windows by installing Python, and adding all the PyQt extras. For this software, it is not required to compile everything.

For Mac OS, you will need the Mac OS X binary, which will allow you to install PyQt on your terminal.

For Linux, you will discover that Python is installed by default. Therefore, you will only need to install PyQt software, package manager.

Resources

Top comments (0)