A summary of a demo development process for Python using the QT5 development interface

Python using QT5 development interface of a demo development process summary

1. Current python version:


2. Use PIP to install QT5:

pip install pyqt5


Pyqt5-tools: PIP install pyqt5-tools


4. Check whether QT was installed successfully:

from PyQt5 import QtWidgets, QtGui
import sys

app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QWidget();
window.show()
sys.exit(app.exec_())

pops out the following interface :

Pycharm related configuration :

1. Add external Tools

open Settings – & gt; Tools-> External Tools click “+”


2. Add QtDesigner

set

as shown below


3. Add PyUIC

is set as shown below.

Parameters: -m pyqt5.uic. Pyuic $FileName$-o $FileNameWithoutExtension$.py

Parameters: -m pyqt5.uic. Pyuic $FileName$-o $FileNameWithoutExtension$.py


3. Create a new PyQt demo and create a project

as shown below


Open QtDesigner

as shown below

open Qt interface as shown in the figure below

create a Main Window

as shown in the figure, you can add your own component

as needed

save

as shown

as shown below, use PyUIC to convert hello. UI file to hello.py

and here’s what I did:

# -*- coding: utf-8 -*-
from helloworld import Ui_MainWindow
from PyQt5 import QtCore, QtGui, QtWidgets
import sys


class query_window(QtWidgets.QMainWindow):
    def __init__(self):
        QtWidgets.QMainWindow.__init__(self)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.pushButton.clicked.connect(self.query_formula)
        # 给button 的 点击动作绑定一个事件处理函数


    def query_formula(self):
        pass
        # 此处编写具体的业务逻辑

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    window = query_window()
    window.show()
    sys.exit(app.exec_())



Read More: