python PyQt5 create project

1 Create a qt project

Set the project path: you can browse and modify the
project name: custom project name, current project yolo_ui

Insert picture description here

Set the compilation environment, currently select qmake

Insert picture description here

Class name: Define a dialog box name
Base class: QDialog dialog-based project

Insert picture description here

Chinese and English selection

Insert picture description here

Choose an effective QT operating environment

Insert picture description here

2. Create a batch file

Set the copy path and file name according to the path, the
compilation environment and the compiled file name

copy ui file path ui current path file name
pyqt compilation environment path -o ui file name after compilation ui file name

echo off 
rem 拷贝ui文件至本目录
copy .\qt_ui\yolo_ui\NumPrdictDlg.ui NumPrdictDlg.ui
rem 用pyuic5 编译.ui文件
C:\Users\DELL\anaconda3\envs\tf20\Scripts\pyuic5 -o ui_NumPrdictDlg.py NumPrdictDlg.ui

Insert picture description here
Execute uic.bat

Copy the ui file from the qt project qt_ui to the local path
Compile the ui file to generate the ui_name.py file

3. Create total interface file

num_predict.py

import sys

from PyQt5.QtCore import *
from PyQt5.QtWidgets import *

# 从UI文件导入
from ui_NumPrdictDlg import Ui_NumPrdictDlg

# 继承UI文件
class QmyDialog(QWidget, Ui_NumPrdictDlg):
    def __init__(self, parent=None):
        super().__init__(parent)
        
        # 初始化UI
        self.ui = Ui_NumPrdictDlg()
        self.ui.setupUi(self)

 
if __name__ == '__main__':
    app = QApplication(sys.argv)
    main_form = QmyDialog()
    main_form.show()

    sys.exit(app.exec_())

Guess you like

Origin blog.csdn.net/weixin_45875105/article/details/112858984