Frontend Development 5 min read

Installing PyQt5 and Converting Qt Designer .ui Files to Python Scripts

This guide explains how to install PyQt5, set up Qt Designer, convert .ui files into Python code with pyuic5, and run a basic PyQt5 window, providing step‑by‑step commands, code snippets, and screenshots for a complete GUI development workflow.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Installing PyQt5 and Converting Qt Designer .ui Files to Python Scripts

PyQt5 is a set of Python bindings for the Qt5 application framework, supporting both Python 2.x and 3.x, and is developed by Riverbank Computing as one of the most powerful GUI libraries.

The package contains more than 620 classes and around 6,000 functions, runs on Unix, Windows, and macOS, and is available under GPL or a commercial license.

The main modules are illustrated in the diagram below:

1. Install PyQt5

<code>pip install pyqt5</code>

2. Convert .ui files to .py files

2.1 Install Qt Designer tools

<code>pip install pyqt5-tools</code>

2.2 Locate the designer executable

Open D:\Python Env\spiders\Lib\site-packages\qt5_applications\Qt\bin\designer.exe , create a simple "Hello pyqt5" window, add a QLabel and set its text to "Hello pyqt5".

Save the UI file (e.g., D:\test\test.ui ) after renaming it as needed.

Open a shell and run pyuic5 to verify that pyqt5-tools is installed correctly.

Convert the UI file to Python code:

<code>pyuic5 -o D:\test\test.py D:\test\test.ui</code>

The conversion creates test.py containing code similar to the following:

<code># -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'D:\test\test.ui'
# Created by: PyQt5 UI code generator 5.15.2
# WARNING: Any manual changes made to this file will be lost when pyuic5 is run again.  Do not edit this file unless you know what you are doing.

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(400, 300)
        self.label = QtWidgets.QLabel(Form)
        self.label.setGeometry(QtCore.QRect(130, 90, 71, 31))
        self.label.setObjectName("label")
        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.label.setText(_translate("Form", "hello word"))
</code>

To display the window, add the following imports and a main block at the end of the file:

<code>import sys
if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_Form()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())
</code>

Running the script launches the simple PyQt5 window as shown in the screenshot below:

code-generationGUIInstallationPyQt5Qt Designer
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.