Skip to content

[Linux ] Use Qt Designer to develop Python GUI program in Ubuntu 18.04

If you want to develop a Python GUI program, choose PyQt5 is a great choice. In the past, I recorded about how to configure the Qt Designer in PyCharm on Windows. ([PyQt5] Tutorial(1) Install PyQt5 and print "Hello World!")

If you want to know more about PyQt5, you can refer to here: https://pypi.org/project/PyQt5/

The installation method in Linux system is actually simpler, the following is a simple record.


Installation of Qt Designer

Before we start, we need to install the following packages:

sudo apt-get install qt5-default
sudo apt-get install qttools5-dev-tools
sudo pip3 install pyqt5


After installing, use the following command to open Qt Designer:

designer

Output:

Let's place a QLabel component in the window, and use ctrl+s to save it, named it UI.ui.


Of course we are not use Python to execute it, we need to convert it from xml format to Python code:

pyuic5 UI.ui -o UI.py

pyuic5 can convert UI files to .py files so that we can read them normally.


Open a new Python file:

from PyQt5 import QtWidgets
from UI import Ui_MainWindow
import sys


class MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.label.setText('Hello World!')


if __name__ == '__main__':
    app = QtWidgets.QApplication([])
    window = MainWindow()
    window.show()
    sys.exit(app.exec_())



Output:

We done!


Leave a ReplyCancel reply

Exit mobile version