1. Install QT Designer
Enter the following command in the terminal of pycharm
//安装pyqt5
pip install PyQt5
//安装pyqt5-tools
pip install pyqt5-tools -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
//安装pyuic
pip install pyuic
Two, configure QT
1. Open pycharm
2. File→Settings→Tools→External Tools
3. Perform relevant configuration here, you can find it yourself, so I won’t go into details here
3. Create a UI file
1. Open pycharm
2. Tools→External Tools→QT Designer
3. Create a Main Window file
4. Drag and drop a Push Button window
5. Click the Export button in the menu bar
6. Lead out the self-created slot function
Fourth, convert the UI file into a py file
1. Select the UI file in the right menu bar
2. Right-click to select the tool → pyuic
5. Modify the function to be called
1. Pay attention here, put the UI file and py file just created into the UI file
2. Create a new py file and write the following code
from UI.MainWindow import Ui_MainWindow
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QCheckBox
from PyQt5.QtCore import pyqtSlot
import cv2
import numpy as np
# ++++++++start---------绑定槽函数显示的方法----------start------------
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent=parent)
self.setupUi(self)
def test(self):
# 这里填自己写的函数
import sys
if __name__ == "__main__":
app = QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())
# --------end---------绑定槽函数显示的方法----------end------------