python gui

We will continue to develop the Qt theme - mainly becuase it is a versatile interface - and it is the only real GUI option available under Linux.

At this point I am assuming that

  • Qt 5.2.1 is installed
  • PyQt5 is installed

Design a screen

Normal Qt operation here.


When you are finished then save the UI test.ui say for this example.

Generate the Python Code

A small utility now pyuic5 to run it type

``bash pyuic5 -x test.ui

The -x just adds the extra "glue" so that you can run the output like



It is easy to get a display running - however you can not add any extra functionality to this class - as the code will be overwritten in any further modifications to the screen.

This is a perfect example of keeping your UI and the code seperate (an Interface almost).

Build your Interface

In this example we will assuming your Interface is called Ui_Form (A standard Name) - and that you saved this ui as display.ui


I use a custom makefile to build this : display.ui
        pyuic5 -x display.ui -o

Add an Implementation class

The original class you should not touch at all... instead create a new file called (You can call it what you want - but you probably should keep their names somewhat aligned).

in this file put the following code

PyQt5 import QtCore, QtGui, QtWidgets
from display import Ui_Form

class display_implement(Ui_Form):
    def __init__(self,*args,**kwargs):
       super(display_implement, self).__init__(*args, **kwargs)

f __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Form = QtWidgets.QWidget()
    ui = Ui_Form()

Now to run the app do the following command


The display should show normally.

Add More to the Display

In the Qt Designed, add a new widget (say another button).

  • Save the UI
  • make (to generate the base UI class)

And test by


You should see the new widget in the inheritied class.