基于pyqt5、mysql、yolov7、chatgpt的小麦病害检测系统v1.0

基于pyqt5、mysql、yolov7、chatgpt的小麦病害检测系统设计与实现

  • 一、界面设计
    • 1.1安装pyqt5
    • 1.2创建用户子窗体
    • 1.3创建管理员主窗体
    • 1.4创建管理员子窗体
    • 1.5创建系统登陆界面
  • 二、环境搭建
    • 2.1pyqt5工具配置
    • 2.2mysql5.7安装
  • 三、编程实现
    • 3.1初始化数据库
    • 3.2创建用户数据库sdk文件
    • 3.3 创建用户主窗体调用子窗体文件_user/User.py
    • 3.4登录界面调用用户管理员界面login_system.py
  • 四、界面展示
  • 五、文档示例

一、界面设计

1.1安装pyqt5

pip install pyqt5-tools

运行 Python安装目录下 Scripts\pyqt5designer.exe 这个可执行文件
1.2创建用户主窗体
进入设计界面创建一个main window
拖动添加控件,创建用户主窗体
具体每个控件怎么使用可以咨询:robot
请添加图片描述

1.2创建用户子窗体

创建qdockwidget,拖动添加控件,创建用户子窗体——检测功能窗体请添加图片描述
……创建其他功能子窗体

1.3创建管理员主窗体

进入设计界面创建一个main window
拖动添加控件,创建管理员主窗体
在这里插入图片描述

1.4创建管理员子窗体

创建qdockwidget,拖动添加控件,创建管理员子窗体——用户信息管理功能窗体
在这里插入图片描述
……创建其他功能子窗体

1.5创建系统登陆界面

进入设计界面创建一个main window
拖动添加控件,效果如下
请添加图片描述

二、环境搭建

2.1pyqt5工具配置

将ui转化为py文件工具配置参考地址1
qrc转_rc.py工具配置参考地址2

生成的_pyuis/user.py文件

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.setWindowModality(QtCore.Qt.WindowModal)
        MainWindow.resize(964, 703)
        MainWindow.setMinimumSize(QtCore.QSize(964, 703))
        MainWindow.setMaximumSize(QtCore.QSize(964, 703))
        MainWindow.setFocusPolicy(QtCore.Qt.NoFocus)
        MainWindow.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
        MainWindow.setWindowOpacity(1.0)
        MainWindow.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
        MainWindow.setDocumentMode(False)
        MainWindow.setDockNestingEnabled(False)
        MainWindow.setDockOptions(QtWidgets.QMainWindow.AllowTabbedDocks|QtWidgets.QMainWindow.AnimatedDocks)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.dockWidget = QtWidgets.QDockWidget(self.centralwidget)
        self.dockWidget.setGeometry(QtCore.QRect(200, 0, 761, 671))
        self.dockWidget.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
        self.dockWidget.setFocusPolicy(QtCore.Qt.NoFocus)
        self.dockWidget.setAcceptDrops(False)
        self.dockWidget.setFloating(False)
        self.dockWidget.setFeatures(QtWidgets.QDockWidget.DockWidgetClosable|QtWidgets.QDockWidget.DockWidgetMovable)
        self.dockWidget.setAllowedAreas(QtCore.Qt.AllDockWidgetAreas)
        self.dockWidget.setObjectName("dockWidget")
        self.dockWidgetContents = QtWidgets.QWidget()
        self.dockWidgetContents.setObjectName("dockWidgetContents")
        self.dockWidget.setWidget(self.dockWidgetContents)
        self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(0, 0, 191, 671))
        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.setObjectName("verticalLayout")
        spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem)
        self.pushButton_2 = QtWidgets.QPushButton(self.verticalLayoutWidget)
        self.pushButton_2.setEnabled(True)
        self.pushButton_2.setMinimumSize(QtCore.QSize(99, 75))
        self.pushButton_2.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.pushButton_2.setAutoDefault(False)
        self.pushButton_2.setDefault(False)
        self.pushButton_2.setFlat(False)
        self.pushButton_2.setObjectName("pushButton_2")
        self.verticalLayout.addWidget(self.pushButton_2)
        spacerItem1 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem1)
        self.pushButton_3 = QtWidgets.QPushButton(self.verticalLayoutWidget)
        self.pushButton_3.setMinimumSize(QtCore.QSize(0, 75))
        self.pushButton_3.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.pushButton_3.setObjectName("pushButton_3")
        self.verticalLayout.addWidget(self.pushButton_3)
        spacerItem2 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem2)
        self.pushButton_5 = QtWidgets.QPushButton(self.verticalLayoutWidget)
        self.pushButton_5.setMinimumSize(QtCore.QSize(0, 75))
        self.pushButton_5.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.pushButton_5.setObjectName("pushButton_5")
        self.verticalLayout.addWidget(self.pushButton_5)
        spacerItem3 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem3)
        self.pushButton_7 = QtWidgets.QPushButton(self.verticalLayoutWidget)
        self.pushButton_7.setMinimumSize(QtCore.QSize(0, 75))
        self.pushButton_7.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.pushButton_7.setObjectName("pushButton_7")
        self.verticalLayout.addWidget(self.pushButton_7)
        spacerItem4 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem4)
        self.pushButton_6 = QtWidgets.QPushButton(self.verticalLayoutWidget)
        self.pushButton_6.setMinimumSize(QtCore.QSize(0, 75))
        self.pushButton_6.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.pushButton_6.setObjectName("pushButton_6")
        self.verticalLayout.addWidget(self.pushButton_6)
        spacerItem5 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem5)
        self.pushButton_4 = QtWidgets.QPushButton(self.verticalLayoutWidget)
        self.pushButton_4.setMinimumSize(QtCore.QSize(0, 75))
        self.pushButton_4.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.pushButton_4.setObjectName("pushButton_4")
        self.verticalLayout.addWidget(self.pushButton_4)
        spacerItem6 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem6)
        self.pushButton = QtWidgets.QPushButton(self.verticalLayoutWidget)
        self.pushButton.setMinimumSize(QtCore.QSize(0, 75))
        self.pushButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.pushButton.setObjectName("pushButton")
        self.verticalLayout.addWidget(self.pushButton)
        spacerItem7 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem7)
        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setCursor(QtGui.QCursor(QtCore.Qt.ForbiddenCursor))
        self.statusbar.setStyleSheet("background-color: rgb(180, 180, 180);")
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "欢迎您"))
        self.dockWidget.setWindowTitle(_translate("MainWindow", "用户功能界面"))
        self.pushButton_2.setText(_translate("MainWindow", "检测病害"))
        self.pushButton_3.setText(_translate("MainWindow", "联系专家"))
        self.pushButton_5.setText(_translate("MainWindow", "病例浏览"))
        self.pushButton_7.setText(_translate("MainWindow", "智能助手"))
        self.pushButton_6.setText(_translate("MainWindow", "检测历史"))
        self.pushButton_4.setText(_translate("MainWindow", "我的主页"))
        self.pushButton.setText(_translate("MainWindow", "设置"))
import a_pictures.pictures_rc

生成的_pyuis/my_home.py文件

from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_DockWidget(object):
    def setupUi(self, DockWidget):
        DockWidget.setObjectName("DockWidget")
        DockWidget.resize(761, 671)
        DockWidget.setMinimumSize(QtCore.QSize(761, 671))
        DockWidget.setMaximumSize(QtCore.QSize(761, 671))
        self.dockWidgetContents = QtWidgets.QWidget()
        self.dockWidgetContents.setObjectName("dockWidgetContents")
        self.groupBox = QtWidgets.QGroupBox(self.dockWidgetContents)
        self.groupBox.setGeometry(QtCore.QRect(30, 19, 681, 161))
        self.groupBox.setTabletTracking(False)
        self.groupBox.setFlat(False)
        self.groupBox.setCheckable(True)
        self.groupBox.setChecked(False)
        self.groupBox.setObjectName("groupBox")
        self.layoutWidget = QtWidgets.QWidget(self.groupBox)
        self.layoutWidget.setGeometry(QtCore.QRect(170, 30, 294, 29))
        self.layoutWidget.setObjectName("layoutWidget")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self.layoutWidget)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.label = QtWidgets.QLabel(self.layoutWidget)
        self.label.setMinimumSize(QtCore.QSize(90, 0))
        self.label.setMaximumSize(QtCore.QSize(16777215, 90))
        self.label.setObjectName("label")
        self.horizontalLayout.addWidget(self.label)
        self.lineEdit = QtWidgets.QLineEdit(self.layoutWidget)
        self.lineEdit.setObjectName("lineEdit")
        self.horizontalLayout.addWidget(self.lineEdit)
        self.layoutWidget_2 = QtWidgets.QWidget(self.groupBox)
        self.layoutWidget_2.setGeometry(QtCore.QRect(170, 70, 294, 29))
        self.layoutWidget_2.setObjectName("layoutWidget_2")
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.layoutWidget_2)
        self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.label_2 = QtWidgets.QLabel(self.layoutWidget_2)
        self.label_2.setMinimumSize(QtCore.QSize(90, 0))
        self.label_2.setMaximumSize(QtCore.QSize(16777215, 90))
        self.label_2.setObjectName("label_2")
        self.horizontalLayout_2.addWidget(self.label_2)
        self.lineEdit_2 = QtWidgets.QLineEdit(self.layoutWidget_2)
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.horizontalLayout_2.addWidget(self.lineEdit_2)
        self.layoutWidget_3 = QtWidgets.QWidget(self.groupBox)
        self.layoutWidget_3.setGeometry(QtCore.QRect(170, 110, 294, 29))
        self.layoutWidget_3.setObjectName("layoutWidget_3")
        self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.layoutWidget_3)
        self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        self.label_4 = QtWidgets.QLabel(self.layoutWidget_3)
        self.label_4.setMinimumSize(QtCore.QSize(90, 0))
        self.label_4.setMaximumSize(QtCore.QSize(16777215, 90))
        self.label_4.setObjectName("label_4")
        self.horizontalLayout_4.addWidget(self.label_4)
        self.lineEdit_4 = QtWidgets.QLineEdit(self.layoutWidget_3)
        self.lineEdit_4.setObjectName("lineEdit_4")
        self.horizontalLayout_4.addWidget(self.lineEdit_4)
        self.pushButton = QtWidgets.QPushButton(self.groupBox)
        self.pushButton.setGeometry(QtCore.QRect(520, 110, 93, 28))
        self.pushButton.setObjectName("pushButton")
        self.groupBox_2 = QtWidgets.QGroupBox(self.dockWidgetContents)
        self.groupBox_2.setGeometry(QtCore.QRect(30, 200, 681, 361))
        self.groupBox_2.setTabletTracking(False)
        self.groupBox_2.setFlat(False)
        self.groupBox_2.setCheckable(True)
        self.groupBox_2.setChecked(False)
        self.groupBox_2.setObjectName("groupBox_2")
        self.layoutWidget_4 = QtWidgets.QWidget(self.groupBox_2)
        self.layoutWidget_4.setGeometry(QtCore.QRect(170, 30, 294, 29))
        self.layoutWidget_4.setObjectName("layoutWidget_4")
        self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.layoutWidget_4)
        self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")
        self.label_5 = QtWidgets.QLabel(self.layoutWidget_4)
        self.label_5.setMinimumSize(QtCore.QSize(90, 0))
        self.label_5.setMaximumSize(QtCore.QSize(16777215, 90))
        self.label_5.setObjectName("label_5")
        self.horizontalLayout_5.addWidget(self.label_5)
        self.lineEdit_5 = QtWidgets.QLineEdit(self.layoutWidget_4)
        self.lineEdit_5.setObjectName("lineEdit_5")
        self.horizontalLayout_5.addWidget(self.lineEdit_5)
        self.layoutWidget_5 = QtWidgets.QWidget(self.groupBox_2)
        self.layoutWidget_5.setGeometry(QtCore.QRect(170, 190, 294, 29))
        self.layoutWidget_5.setObjectName("layoutWidget_5")
        self.horizontalLayout_6 = QtWidgets.QHBoxLayout(self.layoutWidget_5)
        self.horizontalLayout_6.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_6.setObjectName("horizontalLayout_6")
        self.label_6 = QtWidgets.QLabel(self.layoutWidget_5)
        self.label_6.setMinimumSize(QtCore.QSize(90, 0))
        self.label_6.setMaximumSize(QtCore.QSize(16777215, 90))
        self.label_6.setObjectName("label_6")
        self.horizontalLayout_6.addWidget(self.label_6)
        self.lineEdit_6 = QtWidgets.QLineEdit(self.layoutWidget_5)
        self.lineEdit_6.setObjectName("lineEdit_6")
        self.horizontalLayout_6.addWidget(self.lineEdit_6)
        self.layoutWidget_6 = QtWidgets.QWidget(self.groupBox_2)
        self.layoutWidget_6.setGeometry(QtCore.QRect(170, 230, 294, 29))
        self.layoutWidget_6.setObjectName("layoutWidget_6")
        self.horizontalLayout_7 = QtWidgets.QHBoxLayout(self.layoutWidget_6)
        self.horizontalLayout_7.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_7.setObjectName("horizontalLayout_7")
        self.label_7 = QtWidgets.QLabel(self.layoutWidget_6)
        self.label_7.setMinimumSize(QtCore.QSize(90, 0))
        self.label_7.setMaximumSize(QtCore.QSize(16777215, 90))
        self.label_7.setObjectName("label_7")
        self.horizontalLayout_7.addWidget(self.label_7)
        self.lineEdit_7 = QtWidgets.QLineEdit(self.layoutWidget_6)
        self.lineEdit_7.setObjectName("lineEdit_7")
        self.horizontalLayout_7.addWidget(self.lineEdit_7)
        self.pushButton_2 = QtWidgets.QPushButton(self.groupBox_2)
        self.pushButton_2.setGeometry(QtCore.QRect(520, 310, 93, 28))
        self.pushButton_2.setObjectName("pushButton_2")
        self.layoutWidget_7 = QtWidgets.QWidget(self.groupBox_2)
        self.layoutWidget_7.setGeometry(QtCore.QRect(170, 270, 294, 29))
        self.layoutWidget_7.setObjectName("layoutWidget_7")
        self.horizontalLayout_8 = QtWidgets.QHBoxLayout(self.layoutWidget_7)
        self.horizontalLayout_8.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_8.setObjectName("horizontalLayout_8")
        self.label_8 = QtWidgets.QLabel(self.layoutWidget_7)
        self.label_8.setMinimumSize(QtCore.QSize(90, 0))
        self.label_8.setMaximumSize(QtCore.QSize(16777215, 90))
        self.label_8.setObjectName("label_8")
        self.horizontalLayout_8.addWidget(self.label_8)
        self.lineEdit_8 = QtWidgets.QLineEdit(self.layoutWidget_7)
        self.lineEdit_8.setObjectName("lineEdit_8")
        self.horizontalLayout_8.addWidget(self.lineEdit_8)
        self.layoutWidget_8 = QtWidgets.QWidget(self.groupBox_2)
        self.layoutWidget_8.setGeometry(QtCore.QRect(170, 150, 294, 29))
        self.layoutWidget_8.setObjectName("layoutWidget_8")
        self.horizontalLayout_9 = QtWidgets.QHBoxLayout(self.layoutWidget_8)
        self.horizontalLayout_9.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_9.setObjectName("horizontalLayout_9")
        self.label_9 = QtWidgets.QLabel(self.layoutWidget_8)
        self.label_9.setMinimumSize(QtCore.QSize(90, 0))
        self.label_9.setMaximumSize(QtCore.QSize(16777215, 90))
        self.label_9.setObjectName("label_9")
        self.horizontalLayout_9.addWidget(self.label_9)
        self.lineEdit_9 = QtWidgets.QLineEdit(self.layoutWidget_8)
        self.lineEdit_9.setObjectName("lineEdit_9")
        self.horizontalLayout_9.addWidget(self.lineEdit_9)
        self.layoutWidget_9 = QtWidgets.QWidget(self.groupBox_2)
        self.layoutWidget_9.setGeometry(QtCore.QRect(170, 110, 294, 29))
        self.layoutWidget_9.setObjectName("layoutWidget_9")
        self.horizontalLayout_10 = QtWidgets.QHBoxLayout(self.layoutWidget_9)
        self.horizontalLayout_10.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_10.setObjectName("horizontalLayout_10")
        self.label_10 = QtWidgets.QLabel(self.layoutWidget_9)
        self.label_10.setMinimumSize(QtCore.QSize(90, 0))
        self.label_10.setMaximumSize(QtCore.QSize(16777215, 90))
        self.label_10.setObjectName("label_10")
        self.horizontalLayout_10.addWidget(self.label_10)
        self.lineEdit_10 = QtWidgets.QLineEdit(self.layoutWidget_9)
        self.lineEdit_10.setObjectName("lineEdit_10")
        self.horizontalLayout_10.addWidget(self.lineEdit_10)
        self.layoutWidget_10 = QtWidgets.QWidget(self.groupBox_2)
        self.layoutWidget_10.setGeometry(QtCore.QRect(170, 70, 294, 29))
        self.layoutWidget_10.setObjectName("layoutWidget_10")
        self.horizontalLayout_11 = QtWidgets.QHBoxLayout(self.layoutWidget_10)
        self.horizontalLayout_11.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_11.setObjectName("horizontalLayout_11")
        self.label_11 = QtWidgets.QLabel(self.layoutWidget_10)
        self.label_11.setMinimumSize(QtCore.QSize(90, 0))
        self.label_11.setMaximumSize(QtCore.QSize(16777215, 90))
        self.label_11.setObjectName("label_11")
        self.horizontalLayout_11.addWidget(self.label_11)
        self.lineEdit_11 = QtWidgets.QLineEdit(self.layoutWidget_10)
        self.lineEdit_11.setObjectName("lineEdit_11")
        self.horizontalLayout_11.addWidget(self.lineEdit_11)
        self.layoutWidget_11 = QtWidgets.QWidget(self.groupBox_2)
        self.layoutWidget_11.setGeometry(QtCore.QRect(170, 310, 294, 29))
        self.layoutWidget_11.setObjectName("layoutWidget_11")
        self.horizontalLayout_12 = QtWidgets.QHBoxLayout(self.layoutWidget_11)
        self.horizontalLayout_12.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_12.setObjectName("horizontalLayout_12")
        self.label_12 = QtWidgets.QLabel(self.layoutWidget_11)
        self.label_12.setMinimumSize(QtCore.QSize(90, 0))
        self.label_12.setMaximumSize(QtCore.QSize(16777215, 90))
        self.label_12.setObjectName("label_12")
        self.horizontalLayout_12.addWidget(self.label_12)
        self.lineEdit_12 = QtWidgets.QLineEdit(self.layoutWidget_11)
        self.lineEdit_12.setObjectName("lineEdit_12")
        self.horizontalLayout_12.addWidget(self.lineEdit_12)
        self.dateEdit = QtWidgets.QDateEdit(self.groupBox_2)
        self.dateEdit.setGeometry(QtCore.QRect(470, 150, 110, 27))
        self.dateEdit.setObjectName("dateEdit")
        DockWidget.setWidget(self.dockWidgetContents)

        self.retranslateUi(DockWidget)
        QtCore.QMetaObject.connectSlotsByName(DockWidget)

    def retranslateUi(self, DockWidget):
        _translate = QtCore.QCoreApplication.translate
        DockWidget.setWindowTitle(_translate("DockWidget", "我的主页"))
        self.groupBox.setTitle(_translate("DockWidget", "修改密码"))
        self.label.setText(_translate("DockWidget", "

原密码

"
)) self.label_2.setText(_translate("DockWidget", "

新密码

"
)) self.label_4.setText(_translate("DockWidget", "

再次输入

"
)) self.pushButton.setText(_translate("DockWidget", "确认修改")) self.groupBox_2.setTitle(_translate("DockWidget", "完善个人信息")) self.label_5.setText(_translate("DockWidget", "

姓名

"
)) self.label_6.setText(_translate("DockWidget", "

电话号

"
)) self.label_7.setText(_translate("DockWidget", "

身份证号

"
)) self.pushButton_2.setText(_translate("DockWidget", "确认完善")) self.label_8.setText(_translate("DockWidget", "

现住址

"
)) self.label_9.setText(_translate("DockWidget", "

出生日期

"
)) self.label_10.setText(_translate("DockWidget", "

民族

"
)) self.label_11.setText(_translate("DockWidget", "

性别

"
)) self.label_12.setText(_translate("DockWidget", "

学历

"
)) import a_pictures.pictures_rc

生成的_pyuis/login.py文件

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.setEnabled(True)
        MainWindow.resize(480, 389)
        MainWindow.setMaximumSize(QtCore.QSize(480, 389))
        MainWindow.setSizeIncrement(QtCore.QSize(480, 389))
        font = QtGui.QFont()
        font.setFamily("隶书")
        font.setPointSize(9)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        MainWindow.setFont(font)
        MainWindow.setWindowOpacity(0.9)
        MainWindow.setStyleSheet("background-color: rgb(239, 239, 239);\n"
"font: 9pt \"隶书\";")
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
        self.centralwidget.setObjectName("centralwidget")
        self.widget = QtWidgets.QWidget(self.centralwidget)
        self.widget.setGeometry(QtCore.QRect(20, 120, 441, 201))
        font = QtGui.QFont()
        font.setFamily("隶书")
        font.setPointSize(9)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.widget.setFont(font)
        self.widget.setAutoFillBackground(False)
        self.widget.setStyleSheet("background-color: rgb(223, 223, 223);")
        self.widget.setObjectName("widget")
        self.formLayoutWidget = QtWidgets.QWidget(self.widget)
        self.formLayoutWidget.setGeometry(QtCore.QRect(20, 30, 261, 74))
        self.formLayoutWidget.setObjectName("formLayoutWidget")
        self.formLayout = QtWidgets.QFormLayout(self.formLayoutWidget)
        self.formLayout.setContentsMargins(0, 0, 0, 0)
        self.formLayout.setObjectName("formLayout")
        self.label = QtWidgets.QLabel(self.formLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("隶书")
        font.setPointSize(9)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.label.setFont(font)
        self.label.setObjectName("label")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.label)
        self.lineEdit = QtWidgets.QLineEdit(self.formLayoutWidget)
        self.lineEdit.setStyleSheet("background-color: rgb(255, 255, 255);\n"
"font: 75 9pt \"ADMUI3Lg\";")
        self.lineEdit.setObjectName("lineEdit")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.lineEdit)
        spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.formLayout.setItem(1, QtWidgets.QFormLayout.FieldRole, spacerItem)
        self.label_2 = QtWidgets.QLabel(self.formLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("隶书")
        font.setPointSize(9)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.label_2)
        self.lineEdit_2 = QtWidgets.QLineEdit(self.formLayoutWidget)
        self.lineEdit_2.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.lineEdit_2)
        self.horizontalLayoutWidget = QtWidgets.QWidget(self.widget)
        self.horizontalLayoutWidget.setGeometry(QtCore.QRect(19, 120, 261, 31))
        self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.pushButton = QtWidgets.QPushButton(self.horizontalLayoutWidget)
        self.pushButton.setMaximumSize(QtCore.QSize(77, 16777215))
        font = QtGui.QFont()
        font.setFamily("隶书")
        font.setPointSize(9)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.pushButton.setFont(font)
        self.pushButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.pushButton.setStyleSheet("selection-background-color: rgb(0, 0, 0);")
        self.pushButton.setDefault(False)
        self.pushButton.setObjectName("pushButton")
        self.horizontalLayout.addWidget(self.pushButton)
        spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem1)
        self.pushButton_2 = QtWidgets.QPushButton(self.horizontalLayoutWidget)
        self.pushButton_2.setMaximumSize(QtCore.QSize(77, 16777215))
        font = QtGui.QFont()
        font.setFamily("隶书")
        font.setPointSize(9)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.pushButton_2.setFont(font)
        self.pushButton_2.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.pushButton_2.setStyleSheet("selection-background-color: rgb(0, 0, 0);")
        self.pushButton_2.setDefault(True)
        self.pushButton_2.setObjectName("pushButton_2")
        self.horizontalLayout.addWidget(self.pushButton_2)
        spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem2)
        self.pushButton_3 = QtWidgets.QPushButton(self.horizontalLayoutWidget)
        self.pushButton_3.setMaximumSize(QtCore.QSize(77, 16777215))
        font = QtGui.QFont()
        font.setFamily("隶书")
        font.setPointSize(9)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.pushButton_3.setFont(font)
        self.pushButton_3.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.pushButton_3.setStyleSheet("selection-background-color: rgb(0, 0, 0);")
        self.pushButton_3.setObjectName("pushButton_3")
        self.horizontalLayout.addWidget(self.pushButton_3)
        self.label_3 = QtWidgets.QLabel(self.widget)
        self.label_3.setGeometry(QtCore.QRect(320, 20, 81, 101))
        self.label_3.setObjectName("label_3")
        self.horizontalLayoutWidget_2 = QtWidgets.QWidget(self.widget)
        self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(20, 160, 261, 31))
        self.horizontalLayoutWidget_2.setObjectName("horizontalLayoutWidget_2")
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_2)
        self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        spacerItem3 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_2.addItem(spacerItem3)
        self.radioButton_2 = QtWidgets.QRadioButton(self.horizontalLayoutWidget_2)
        font = QtGui.QFont()
        font.setFamily("隶书")
        font.setPointSize(9)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.radioButton_2.setFont(font)
        self.radioButton_2.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.radioButton_2.setChecked(True)
        self.radioButton_2.setObjectName("radioButton_2")
        self.horizontalLayout_2.addWidget(self.radioButton_2)
        spacerItem4 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_2.addItem(spacerItem4)
        self.radioButton = QtWidgets.QRadioButton(self.horizontalLayoutWidget_2)
        font = QtGui.QFont()
        font.setFamily("隶书")
        font.setPointSize(9)
        font.setBold(False)
        font.setItalic(False)
        font.setWeight(50)
        self.radioButton.setFont(font)
        self.radioButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.radioButton.setObjectName("radioButton")
        self.horizontalLayout_2.addWidget(self.radioButton)
        spacerItem5 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_2.addItem(spacerItem5)
        self.label_4 = QtWidgets.QLabel(self.widget)
        self.label_4.setGeometry(QtCore.QRect(290, 150, 141, 31))
        self.label_4.setObjectName("label_4")
        self.label_5 = QtWidgets.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(70, 20, 341, 81))
        self.label_5.setObjectName("label_5")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 480, 21))
        self.menubar.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.menubar.setStyleSheet("background-color: rgb(213, 213, 213);\n"
"selection-background-color: rgb(0, 0, 0);")
        self.menubar.setObjectName("menubar")
        self.menu = QtWidgets.QMenu(self.menubar)
        self.menu.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.menu.setObjectName("menu")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setCursor(QtGui.QCursor(QtCore.Qt.ForbiddenCursor))
        self.statusbar.setStyleSheet("background-color: rgb(213, 213, 213);\n"
"")
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionjhhjhj = QtWidgets.QAction(MainWindow)
        font = QtGui.QFont()
        font.setFamily("隶书")
        self.actionjhhjhj.setFont(font)
        self.actionjhhjhj.setObjectName("actionjhhjhj")
        self.actiondd = QtWidgets.QAction(MainWindow)
        font = QtGui.QFont()
        font.setFamily("隶书")
        self.actiondd.setFont(font)
        self.actiondd.setObjectName("actiondd")
        self.action1 = QtWidgets.QAction(MainWindow)
        self.action1.setObjectName("action1")
        self.menu.addAction(self.actionjhhjhj)
        self.menu.addAction(self.actiondd)
        self.menu.addSeparator()
        self.menu.addAction(self.action1)
        self.menubar.addAction(self.menu.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "登录"))
        self.label.setText(_translate("MainWindow", "账号"))
        self.label_2.setText(_translate("MainWindow", "密码"))
        self.pushButton.setText(_translate("MainWindow", "注册"))
        self.pushButton_2.setText(_translate("MainWindow", "登录"))
        self.pushButton_3.setText(_translate("MainWindow", "找回密码"))
        self.label_3.setText(_translate("MainWindow", "

"
)) self.radioButton_2.setText(_translate("MainWindow", "用户")) self.radioButton.setText(_translate("MainWindow", "管理员")) self.label_4.setText(_translate("MainWindow", "

欢迎使用...

"
)) self.label_5.setText(_translate("MainWindow", "

小麦病害识别系统

河南科技学院

"
)) self.menu.setTitle(_translate("MainWindow", "主菜单")) self.actionjhhjhj.setText(_translate("MainWindow", "关于我们")) self.actiondd.setText(_translate("MainWindow", "帮助")) self.action1.setText(_translate("MainWindow", "数据库配置")) import a_pictures.pictures_rc

2.2mysql5.7安装

安装包链接: https://pan.baidu.com/s/1uA–xggCc0HKXuA3IpluBg 提取码: 4r5x
安装需要勾选MySQL Server 以及MySQL Workbench进行安装

安装出现关于Microsoft Visual c++ 2013的报错可以看看这个

三、编程实现

3.1初始化数据库

确保数据库处于运行状态
请添加图片描述
初始化数据库
a_data_sheets/lowp.sql文件

drop database lowp;

create database lowp;

use lowp;

create table User
(
	Student_Id varchar(20) primary key, 
	Phone_Num varchar(20), 
	Name varchar(20) not null, 
    Password varchar(20) default "12345678"
);

create table User_Detailed_Info
(
	Student_Id varchar(20) primary key, 
    Gender varchar(20),
    Nation varchar(20), 
    Data_Birth date, 
    Id_Num varchar(20), 
    Pre_Address varchar(20), 
    Record_School varchar(20)
);

create table User_Set_Up
(
	Student_Id varchar(20) primary key,
	Bg_Color varchar(20) default "#EFEFEF",
	Bg_Picture longblob,
    Pellucidity double default 1.0,
	Font_Color varchar(20) default "#000000",
	Font varchar(20) default "隶书",
    Font_Size int(10) default 12,
    Tcp_Ip varchar(20) default "127.0.0.1",
    Tcp_port varchar(20) default "3306"
);


create table Expert
(
	Numbering varchar(20) primary key,
    Name varchar(20) not null,
    Areas varchar(20) not null,
    Phone_Num varchar(20) not null
);

3.2创建用户数据库sdk文件

_mysqlsdk/login.py文件

import pymysql
class Login:
    def __init__(self, host="127.0.0.1", user="root", password="123456", db='lowp', port=3306):
        self.conn = pymysql.connect(host=host, user=user, password=password, db=db, port=port, charset='utf8')

    def __del__(self):
        try:
            self.conn.close()
        except AttributeError:
            print("数据库初始化错误...")

_mysqlsdk/user.py文件

import pymysql
import numpy as np


class User_Sdk:
    def __init__(self, conn: pymysql.connections.Connection):
        self.conn = conn
        self.shutdown_safe()

    # 关闭mysql系统安全模式
    def shutdown_safe(self):
        try:
            cursor = self.conn.cursor()
            sql = "set sql_safe_updates = 0;"
            cursor.execute(sql)
            self.conn.commit()
            cursor.close()
            return True
        except Exception as err:
            print(err)
            return False

    # 用于重置用户的一些表格。
    def init_tables(self, user_name):
        try:
            cursor = self.conn.cursor()
            sql = ["""delete from user_detailed_info where Student_Id=%s;""",
                   """insert into user_detailed_info (Student_Id) values (%s);""",]
            for sql_n in sql:
                cursor.execute(sql_n, (user_name,))
                self.conn.commit()
            cursor.close()
            return True
        except Exception as err:
            print(err)
            return False

    # 用于向user表中插入一条记录,记录了用户的姓名、手机号码、密码等信息。
    def save_user(self, user_name: str, phone_num: str, name: str, password: str):
        try:
            cursor = self.conn.cursor()
            sql = "insert into user (Student_Id, Phone_Num, Name, Password) values (%s, %s, %s, %s)"
            cursor.execute(sql, (user_name, phone_num, name, password))
            self.conn.commit()
            cursor.close()
            return True
        except Exception as err:
            print(err)
            return False

    # 用于查找指定用户的信息,根据输入的学号返回用户的所有信息。
    def find_user(self, user_name: str):
        try:
            cursor = self.conn.cursor()
            sql = "select * from user where Student_Id=%s"
            cursor.execute(sql, (user_name,))
            self.conn.commit()
            data = cursor.fetchall()
            cursor.close()
            return data
        except Exception as err:
            print(err)
            return tuple()

    # 用于将用户上传的图片识别结果保存到数据库中。该方法接收三个参数:image是一个numpy数组,存储的是用户上传的图片;user_name表示用户的学号;result则是图片的识别结果。
    def save_identify_res(self, image: np.ndarray, user_name: str, result: str):
        image_bytes = image.tobytes()
        try:
            cursor = self.conn.cursor()
            sql = "insert into identify_result (Student_Id, Res_Picture, Result) values (%s, %s, %s)"
            cursor.execute(sql, (user_name, image_bytes, result))
            self.conn.commit()
            cursor.close()
            return True
        except Exception as err:
            print(err)
            return False


    # 用于更新用户的密码。
    def update_password(self, user_name: str, new_password: str):
        try:
            cursor = self.conn.cursor()
            sql = "update user set Password=%s where Student_Id=%s"
            cursor.execute(sql, (new_password, user_name))
            self.conn.commit()
            cursor.close()
            return True
        except Exception as err:
            print(err)
            return False

    # 用于将用户自己的详细信息保存到数据库中。
    def save_oneself_data(self, user_name: str, gender: str, nation: str, data_birth: str, id_num: str, pre_address: str,
                          record_school: str):
        try:
            cursor = self.conn.cursor()
            sql = "update user_detailed_info set Nation=%s, Data_Birth=%s, Gender=%s, Id_Num=%s, Pre_Address=%s, Record_School=%s where Student_Id=%s"
            cursor.execute(sql, (nation, data_birth, gender, id_num, pre_address, record_school, user_name))
            self.conn.commit()
            cursor.close()
            return True
        except Exception as err:
            print(err)
            return False

    # 用于将用户自己的用户信息初始化到详细信息数据表中。
    def init_oneself_data(self, user_name: str):
        try:
            cursor = self.conn.cursor()
            sql = "insert into user_detailed_info (Student_Id) values (%s)"
            cursor.execute(sql, (user_name,))
            self.conn.commit()
            cursor.close()
            return True
        except Exception as err:
            print(err)
            return False

    # 用于查找用户的详细信息。
    def find_oneself_data(self, user_name: str):
        try:
            cursor = self.conn.cursor()
            sql = "select * from user_detailed_info where Student_Id=%s"
            cursor.execute(sql, (user_name,))
            self.conn.commit()
            data = cursor.fetchall()
            cursor.close()
            return data
        except Exception as err:
            print(err)
            return tuple()

    # 用于初始化用户界面个性化设置。
    def save_init_user_set_up(self, user_name):
        try:
            cursor = self.conn.cursor()
            sql = "insert into user_set_up (Student_Id) values (%s)"
            cursor.execute(sql, (user_name,))
            self.conn.commit()
            cursor.close()
            return True
        except Exception as err:
            print(err)
            return False

3.3 创建用户主窗体调用子窗体文件_user/User.py

import sys
from _pyuis import user, my_home
from PyQt5.QtWidgets import QApplication, QMainWindow, QDockWidget, QFileDialog, QColorDialog, QWidget, QLabel, \
    QPushButton, QLineEdit, QProgressBar, QTextBrowser, QMessageBox, QStyledItemDelegate, QDialog, QGridLayout
from PyQt5 import QtCore
from _mysqlsdk import user1 as mysql_user_
from _mysqlsdk.login import Login
import pymysql


def my_exception_hook(type, value, traceback):
    # 自定义异常处理程序
    print(type)
    print(value)
    print(traceback)


class User(QMainWindow, user.Ui_MainWindow):

    # 构造函数
    def __init__(self, student_id, login_root):
        global mysql_user

        mysql_user = mysql_user_.User_Sdk(login_root)

        super().__init__()  # 调用父类构造函数
        self.student_id = student_id  # 学号
        self.child_objects = [None, None, None, None, None, None, None]  # 初始化功能界面对象列表
        self.example_objects = [None, None, None, None, None, None, None]
        self.child_windows = list()  # 初始化窗体
        self.setupUi(self)  # 调用父类setupUi()函数,设置界面控件

        # 将窗体赋予QDockWidget()属性
        for i in range(0, 7):
            self.child_windows.append(QDockWidget())

        # 实例化对象
        self.child_objects[5] = my_home.Ui_DockWidget()
        self.pushButton_4.clicked.connect(lambda: self.disease_detection(5))

    # 鼠标点击槽函数
    def disease_detection(self, num):
        [window_n.close() for window_n in self.child_windows if window_n.isVisible()]  # 判断功能窗体列表中的窗体是否打开,如果打开则对其做关闭处理。

        self.child_windows[num] = QDockWidget(self)  # 将DockWidget窗体加入至self(用户)窗体中
        self.child_windows[num].setGeometry(QtCore.QRect(200, 0, 761, 671))  # 设置其位置与尺寸
        self.child_objects[num].setupUi(self.child_windows[num])  # 将功能窗体赋值给子窗体(功能窗体)
        if num == 5:
            self.example_objects[num] = My_Home(self.child_objects[num], self.student_id)
            self.child_objects[num].pushButton.clicked.connect(self.example_objects[num].change_password)
            self.child_objects[num].pushButton_2.clicked.connect(self.example_objects[num].change_information)
            self.child_objects[num].dateEdit.dateChanged.connect(self.example_objects[num].set_txt)
        self.child_windows[num].show()  # 展示功能窗体

    # 界面清空的时候清除界面存留对象等
    def clear_win_rubbish(self):
        pass


class My_Home:
    def __init__(self, win_object: my_home.Ui_DockWidget, student_id: str):
        self.win_object = win_object
        self.win_object.lineEdit.setEchoMode(2)  # 设置密码不可见
        self.win_object.lineEdit_2.setEchoMode(2)
        self.win_object.lineEdit_4.setEchoMode(2)
        self.win_object.lineEdit_5.setFocusPolicy(QtCore.Qt.NoFocus)
        self.win_object.lineEdit_6.setFocusPolicy(QtCore.Qt.NoFocus)
        # self.win_object.lineEdit_9.setFocusPolicy(QtCore.Qt.NoFocus)
        self.win_object.lineEdit_11.setText('男')
        # self.win_object.lineEdit_9.setInputMask('####-##-##')
        self.student_id = student_id
        self.name = None
        self.gender = None
        self.nation = None
        self.phone = None
        self.address = None
        self.id_card = None
        self.education = None
        self.date = None
        user_info = mysql_user.find_oneself_data(self.student_id)[0]
        user_info2 = mysql_user.find_user(self.student_id)[0]
        self.password = user_info2[3]
        self.name = self.win_object.lineEdit_5.setText(user_info2[2])
        self.gender = self.win_object.lineEdit_11.setText(user_info[1])
        self.nation = self.win_object.lineEdit_10.setText(user_info[2])
        self.age = self.win_object.lineEdit_9.setText(str(user_info[3]))
        self.phone = self.win_object.lineEdit_6.setText(user_info2[1])
        self.address = self.win_object.lineEdit_8.setText(user_info[5])
        self.id_card = self.win_object.lineEdit_7.setText(user_info[4])
        self.education = self.win_object.lineEdit_12.setText(user_info[6])
        if user_info[3] != None:
            self.win_object.dateEdit.setDate(user_info[3])

    def change_password(self):
        current_password = self.win_object.lineEdit.text()
        if current_password != self.password:
            QMessageBox.warning(QWidget(), "警告", "密码错误!")
            return
        else:
            new_password = self.win_object.lineEdit_2.text()
            new_password2 = self.win_object.lineEdit_4.text()
            if current_password == new_password:
                QMessageBox.warning(QWidget(), "警告", "新密码不能与旧密码相同!")
                return
            if len(new_password) < 8:
                QMessageBox.warning(QWidget(), "警告", "密码长度不能小于8位!")
                return
            if new_password != new_password2:
                QMessageBox.warning(QWidget(), "警告", "两次输入的密码不一致!")
                return
            else:
                mysql_user.update_password(self.student_id, new_password)
                QMessageBox.information(QWidget(), "提示", "密码修改成功!")
                return

    def change_information(self):

        self.gender = self.win_object.lineEdit_11.text()
        self.nation = self.win_object.lineEdit_10.text()
        self.address = self.win_object.lineEdit_8.text()
        self.id_card = self.win_object.lineEdit_7.text()
        self.education = self.win_object.lineEdit_12.text()
        # if self.win_object.lineEdit_11.text() != '男' or self.win_object.lineEdit_11.text() != '女':
        #     QMessageBox.warning(QWidget(), "警告", "性别信息错误!")
        #     return
        # else:
        mysql_user.save_oneself_data(self.student_id, self.gender, self.nation, self.date, self.id_card, self.address,
                                     self.education)
        QMessageBox.warning(QWidget(), "提示", "信息修改成功!")

    def set_txt(self):
        self.date = self.win_object.dateEdit.date().toPyDate()
        self.win_object.lineEdit_9.setText(self.date.strftime('%Y-%m-%d'))


if __name__ == '__main__':
    sys.excepthook = my_exception_hook  # 若出错,输出错误
    app = QApplication(sys.argv)  # 创建 QApplication 实例对象
    login = Login()
    mysql_user = mysql_user_.User_Sdk(login.conn)
    window = User('20202214222', login.conn)  # 实例化window用户窗体对象
    window.show()  # 显示窗口
    app.exit(app.exec_())  # 启动主事件循环

3.4登录界面调用用户管理员界面login_system.py

import os
import sys
from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QDialog, QLineEdit
from _mysqlsdk import login as Mysql_Login
from _mysqlsdk import user as mysql_user_
from _pyuis import login, register, retrieve_password, about, author_information, register_root, retrieve_pwd_root, database_setup, help
from _user.User import User

root_path = os.getcwd()



class Login(QMainWindow, login.Ui_MainWindow):

    # 构造函数
    def __init__(self):
        super().__init__()  # 调用父类构造函数
        self.setupUi(self)  # 初始化窗体
        self.setWindowIcon(
            QtGui.QIcon('a_pictures/logo.png'))  # 设置窗体图标
        self.setWindowTitle('登录系统')  # 设置窗体标题

        self.account = None  # 账号
        self.password = None  # 密码
        self.user = None
        self.admin = None
        self.database_setup = None

        self.pushButton_2.clicked.connect(self.login)  # 登录按钮绑定登录函数
        self.pushButton_2.setShortcut('Return')  # 设置登录按钮快捷键
        self.pushButton.clicked.connect(self.register)  # 注册按钮绑定注册函数
        self.pushButton_3.clicked.connect(self.retrieve_password)  # 忘记密码按钮绑定忘记密码函数
        self.actionjhhjhj.triggered.connect(self.about_us)  # 菜单栏绑定函数
        self.actiondd.triggered.connect(self.help)  # 菜单栏绑定函数
        self.action1.triggered.connect(self.database)  # 菜单栏绑定函数
        self.lineEdit_2.setEchoMode(2)  # 设置密码输入框为密码模式

        self.close_control()

        self.mysql_user = None
        self.mysql_administrator = None
        self.login_root = None

        self.Retrieve_password = None
        self.Register = None
        self.About = None

    def close_control(self):
        self.lineEdit.setEnabled(False)
        self.lineEdit_2.setEnabled(False)
        self.pushButton.setEnabled(False)
        self.pushButton_2.setEnabled(False)
        self.pushButton_3.setEnabled(False)

    def open_control(self):
        self.lineEdit.setEnabled(True)
        self.lineEdit_2.setEnabled(True)
        self.pushButton.setEnabled(True)
        self.pushButton_2.setEnabled(True)
        self.pushButton_3.setEnabled(True)

    def login(self):
        self.account = self.lineEdit.text()
        self.password = self.lineEdit_2.text()
        if self.account == '' or self.password == '':
            QMessageBox.critical(self, '错误', '账号密码不能为空', QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
            return
        if self.radioButton_2.isChecked():
            user_info = self.mysql_user.find_user(self.account)
            if user_info != ():  # 判断是否存在该用户
                if self.account == user_info[0][0] and self.password == user_info[0][3]:
                    print(user_info[0][2], '登录成功')
                    user_setting = self.mysql_user.find_user_set_up(self.account)
                    background_color = user_setting[0][1]
                    transparency = user_setting[0][3]
                    font_color = user_setting[0][4]
                    font_family = user_setting[0][5]
                    font_size = user_setting[0][6]
                    self.user = User(self.account, self.login_root.conn)
                    self.user.setStyleSheet('font-family: %s;font-size:%spt;background-color: %s;color: %s' % (
                        font_family, font_size, background_color, font_color))
                    self.user.setFont(QtGui.QFont(font_family, 10))
                    self.user.setWindowIcon(
                        QtGui.QIcon('a_pictures/logo.png'))
                    self.user.setWindowOpacity(transparency)
                    self.user.show()
                    self.close()
                    return
                else:
                    QMessageBox.critical(self, '错误', '请检查账号密码是否正确', QMessageBox.Yes | QMessageBox.No,
                                         QMessageBox.Yes)
                    print('登录失败')
            else:
                QMessageBox.critical(self, '错误', '该用户不存在', QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
                print('登录失败')

    def register(self):
        if self.radioButton_2.isChecked():
            self.Register = Register(self.mysql_user)
            self.Register.show()
        else:
            self.Register = Register_Root(self.mysql_administrator)
            self.Register.show()

    def retrieve_password(self):
        if self.radioButton_2.isChecked():
            self.Retrieve_password = Retrieve(self.mysql_user)
            self.Retrieve_password.show()
        else:
            self.Retrieve_password = Retrieve_Root(self.mysql_administrator)
            self.Retrieve_password.show()

    def about_us(self):
        self.About = About()
        self.About.show()

    def help(self):
        self.help = Help()
        self.help.show()

    def database(self):
        self.database_setup = Database_Setup()
        self.database_setup.show()
        self.database_setup.exec_()
        if self.database_setup.flag_open:
            self.open_control()
            try:
                self.login_root = Mysql_Login.Login(self.database_setup.database['host'],
                                                    self.database_setup.database['user'],
                                                    self.database_setup.database['password'],
                                                    self.database_setup.database['database'],
                                                    self.database_setup.database['port'])
                self.mysql_user = mysql_user_.User_Sdk(self.login_root.conn)

            except Exception as err:
                QMessageBox.critical(self, '错误', str(err), QMessageBox.Yes)
                self.close_control()
        else:
            QMessageBox.critical(self, '错误', '数据库配置失败!', QMessageBox.Yes)


class Register(QMainWindow, register.Ui_Form):
    def __init__(self, mysql_user):
        super().__init__()
        self.setupUi(self)
        self.setWindowIcon(QtGui.QIcon('../a_picture/logo.png'))  # 设置窗体图标
        self.setWindowTitle('注册系统')  # 设置窗体标题

        self.student_id = None
        self.phone_number = None
        self.name = None
        self.password = None
        self.mysql_user = mysql_user
        self.pushButton.clicked.connect(self.register)
        self.lineEdit_4.setEchoMode(2)  # 设置密码输入框为密码模式
        self.lineEdit_5.setEchoMode(2)  # 设置密码输入框为密码模式

    def register(self):
        if self.lineEdit.text() == "":
            QMessageBox.warning(self, '警告', '学号不能为空,请输入!')
        elif self.lineEdit_2.text() == "":
            QMessageBox.warning(self, '警告', '手机号不能为空,请输入!')
        elif self.lineEdit_3.text() == "":
            QMessageBox.warning(self, '警告', '姓名不能为空,请输入!')
        elif self.lineEdit_4.text() == "":
            QMessageBox.warning(self, '警告', '密码不能为空,请输入!')
        else:
            self.student_id = self.lineEdit.text()
            self.phone_number = self.lineEdit_2.text()
            self.name = self.lineEdit_3.text()
            self.password = self.lineEdit_4.text()
            if len(self.password) <= 8:
                QMessageBox.warning(self, '警告', '密码长度不符合要求,需8位以上,请重新输入!')
            elif self.password != self.lineEdit_5.text():
                QMessageBox.warning(self, '警告', '两次输入的密码不一致,请重新输入!')
            else:
                if bool(len(self.mysql_user.find_user(self.student_id))):
                    QMessageBox.warning(self, '警告', '该账号已被注册,请重新输入!')
                    return
                else:
                    if self.mysql_user.save_user(self.student_id, self.phone_number, self.name, self.password):
                        self.mysql_user.init_oneself_data(self.student_id)
                        self.mysql_user.save_init_user_set_up(self.student_id)

                        QMessageBox.information(self, '提示', '注册成功!')
                        self.close()
                        return
                    else:
                        QMessageBox.warning(self, '警告', '注册失败,请重新输入!')
                        return


class Register_Root(QMainWindow, register_root.Ui_Form):
    def __init__(self, mysql_administrator):
        super().__init__()
        self.setupUi(self)
        self.setWindowIcon(QtGui.QIcon('a_pictures/logo.png'))  # 设置窗体图标
        self.setWindowTitle('注册系统')  # 设置窗体标题

        self.student_id = None
        self.phone_number = None
        self.name = None
        self.password = None
        self.mysql_administrator = mysql_administrator
        self.pushButton.clicked.connect(self.register)
        self.lineEdit_4.setEchoMode(2)  # 设置密码输入框为密码模式
        self.lineEdit_5.setEchoMode(2)  # 设置密码输入框为密码模式

    def register(self):
        if self.lineEdit.text() == "":
            QMessageBox.warning(self, '警告', '内部号不能为空,请输入!')
        elif self.lineEdit_2.text() == "":
            QMessageBox.warning(self, '警告', '手机号不能为空,请输入!')
        elif self.lineEdit_3.text() == "":
            QMessageBox.warning(self, '警告', '姓名不能为空,请输入!')
        elif self.lineEdit_4.text() == "":
            QMessageBox.warning(self, '警告', '密码不能为空,请输入!')
        else:
            self.student_id = self.lineEdit.text()
            self.phone_number = self.lineEdit_2.text()
            self.name = self.lineEdit_3.text()
            self.password = self.lineEdit_4.text()
            if len(self.password) <= 8:
                QMessageBox.warning(self, '警告', '密码长度不符合要求,需8位以上,请重新输入!')
            elif self.password != self.lineEdit_5.text():
                QMessageBox.warning(self, '警告', '两次输入的密码不一致,请重新输入!')
            else:
                if bool(len(self.mysql_administrator.find_administrator(self.student_id))):
                    QMessageBox.warning(self, '警告', '该账号已被注册,请重新输入!')
                    return
                else:
                    if self.mysql_administrator.save_administrator(self.student_id, self.phone_number, self.name,
                                                                   self.password):
                        self.mysql_administrator.save_oneself_data(self.student_id)
                        self.mysql_administrator.save_init_admin_set_up(self.student_id)
                        QMessageBox.information(self, '提示', '注册成功!')
                        self.close()
                        return
                    else:
                        QMessageBox.warning(self, '警告', '注册失败,请重新输入!')
                        return


class Retrieve(QMainWindow, retrieve_password.Ui_Form):
    def __init__(self, mysql_user):
        super().__init__()
        self.setupUi(self)
        self.setWindowIcon(
            QtGui.QIcon('a_pictures/logo.png'))  # 设置窗体图标
        self.setWindowTitle('找回密码')  # 设置窗体标题
        self.pushButton.clicked.connect(self.retrieve_password)
        self.account_number = None
        self.phone_number = None
        self.mysql_user = mysql_user

    def retrieve_password(self):
        self.account_number = self.lineEdit.text()
        self.phone_number = self.lineEdit_2.text()
        if self.account_number == '' or self.phone_number == '':
            QMessageBox.warning(self, '警告', '账号或手机号不能为空,请输入!')
            return
        user_info = self.mysql_user.find_user(self.account_number)
        print(user_info)
        if user_info == ():  # 判断是否找到
            QMessageBox.warning(self, '警告', '未找到,请检查是否注册!')
            return
        else:
            if self.account_number == user_info[0][0] and self.phone_number == user_info[0][1]:
                QMessageBox.warning(self, '警告', '您的密码是' + user_info[0][3] + ',请牢记!')
                return
            else:
                QMessageBox.warning(self, '警告', '手机号错误,请重新输入!')
                return


class Retrieve_Root(QMainWindow, retrieve_pwd_root.Ui_Form):
    def __init__(self, mysql_administrator):
        super().__init__()
        self.setupUi(self)
        self.setWindowIcon(
            QtGui.QIcon('a_pictures/logo.png'))  # 设置窗体图标
        self.setWindowTitle('找回密码')  # 设置窗体标题
        self.pushButton.clicked.connect(self.retrieve_password)
        self.account_number = None
        self.phone_number = None
        self.mysql_administrator = mysql_administrator

    def retrieve_password(self):
        self.account_number = self.lineEdit.text()
        self.phone_number = self.lineEdit_2.text()
        if self.account_number == '' or self.phone_number == '':
            QMessageBox.warning(self, '警告', '内部号或手机号不能为空,请输入!')
            return
        user_info = self.mysql_administrator.find_administrator(self.account_number)
        if user_info is None:
            QMessageBox.warning(self, '警告', '未找到,请检查是否注册!')
            return
        else:
            if self.account_number == user_info[0][0] and self.phone_number == user_info[0][1]:
                QMessageBox.warning(self, '警告', '您的密码是' + user_info[0][3] + ',请牢记!')
                return
            else:
                QMessageBox.warning(self, '警告', '手机号错误,请重新输入!')
                return


class About(QMainWindow, about.Ui_Form):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.setWindowIcon(
            QtGui.QIcon('a_pictures/logo.png'))  # 设置窗体图标
        self.setWindowTitle('关于我们')  # 设置窗体标题
        self.wei = None
        self.huang = None
        self.chen = None

        self.pushButton_7.clicked.connect(self.Wei)
        self.pushButton_8.clicked.connect(self.Huang)
        self.pushButton_9.clicked.connect(self.Chen)

    def Wei(self):
        self.wei = About_Win()
        self.wei.setWindowTitle('魏凯杰')  # 设置窗体标题
        self.wei.lineEdit.setText('[email protected]')
        self.wei.lineEdit_2.setText('wLkLjX-forever')
        self.wei.lineEdit_3.setText('魏凯杰')
        self.wei.show()

    def Huang(self):
        self.huang = About_Win()
        self.huang.setWindowTitle('黄启帆')  # 设置窗体标题
        self.huang.lineEdit.setText('[email protected]')
        self.huang.lineEdit_2.setText('hqf15225918309')
        self.huang.lineEdit_3.setText('黄启帆')
        self.huang.show()

    def Chen(self):
        self.chen = About_Win()
        self.chen.setWindowTitle('陈朝辉')  # 设置窗体标题
        self.chen.lineEdit.setText('[email protected]')
        self.chen.lineEdit_2.setText('ChaoHui_Chen1024')
        self.chen.lineEdit_3.setText('陈朝辉')
        self.chen.show()


class About_Win(QMainWindow, author_information.Ui_Form):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.setWindowIcon(
            QtGui.QIcon('a_pictures/logo.png'))  # 设置窗体图标
        self.buttonBox.accepted.connect(self.close)


class Database_Setup(QDialog, database_setup.Ui_Dialog):

    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.flag_open = False
        self.database = dict()
        self.database['host'] = "localhost"
        self.database['port'] = 3306
        self.database['user'] = "root"
        self.database['password'] = "123456"
        self.database['database'] = "lowp"

        self.lineEdit.setText(self.database['user'])
        self.lineEdit_2.setText(self.database['password'])
        self.lineEdit_3.setText(self.database['host'])
        self.lineEdit_4.setText(str(self.database['port']))
        self.lineEdit_5.setText(self.database['database'])

        self.pushButton.clicked.connect(self.setup_button_clicked)

    def setup_button_clicked(self):

        for lineEdit in self.findChildren(QLineEdit):
            if lineEdit.text() == '':
                QMessageBox.warning(self, '警告', '数据库设置不能为空,请输入!')
                self.flag_open = False
                return

        self.database['user'] = self.lineEdit.text()
        self.database['password'] = self.lineEdit_2.text()
        self.database['host'] = self.lineEdit_3.text()
        self.database['port'] = int(self.lineEdit_4.text())
        self.database['database'] = self.lineEdit_5.text()
        QMessageBox.information(self, '提示', '数据库设置成功!')
        self.close()
        self.flag_open = True


class Help(QMainWindow, help.Ui_Form):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.setWindowIcon(
            QtGui.QIcon('a_pictures/logo.png'))  # 设置窗体图标
        self.setWindowTitle('帮助')  # 设置窗体标题


if __name__ == '__main__':
    app = QApplication(sys.argv)  # 创建 QApplication 实例对象
    window = Login()  # 实例化window用户窗体对象
    window.show()  # 显示窗口
    app.exit(app.exec_())  # 启动主事件循环

四、界面展示

在这里插入图片描述

在这里插入图片描述

请添加图片描述
请添加图片描述
请添加图片描述

五、文档示例

在这里插入图片描述

请添加图片描述
请添加图片描述
请添加图片描述

完整功能b站演示视频链接
小麦病害检测系统——本系统基于pyqt5,mysql,yolov7实现了界面友好型的小麦病害检测,包括用户,专家和管理员登录,融合chatgpt实现智能助手。本项目为本人及团队成员2023上半学年软件工程课设,由于余家贫,无从置书以观,故今欲出售,望解诸君之忧,也解吾之困。包含完整可执行程序及资料文档(可行性分析,需求规格说明书,总体设计文档,汇报ppt等)价格详谈。联系方式邮箱[email protected]

你可能感兴趣的:(qt,yolov7,mysql,python,软件工程,小麦病害识别系统,chatgpt)