We could see a simple window with a label on it after executing this simple code:
In this code we created a QApplication and run the event loop via exec_() method.
Using Qt Designer to design UI
In the first example we “designed” an application UI by coding, but in real project we have much more complicated UI for applications which is hard to design without UI designer. For PyQt5, we could use Qt Designer to design UI as before but we need one tiny utility to transform *.ui file into python code.
i.e. If we drawn a simple UI like this in Qt Designer and save it as test.ui:
Then we use pyuic5 to generate python code from test.ui:
Here we defined a class MyMainWindow which inheriting from QMainWindow and Ui_MainWindow, then we defined __init__ method which will setupUi and binding button clicked event with onBtnClicked. When pushButton was clicked, we can see output in terminal:
So far we still not sure about the performance differences between Qt(C++) and PyQt5 but as far as I can see PyQt5 could be one of the options for those engineers who is not very good at C++.