基于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
- 四、界面展示
- 五、文档示例
一、界面设计
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", "<html><head/><body><p align=\"right\">原密码</p></body></html>"))
self.label_2.setText(_translate("DockWidget", "<html><head/><body><p align=\"right\">新密码</p></body></html>"))
self.label_4.setText(_translate("DockWidget", "<html><head/><body><p align=\"right\">再次输入</p></body></html>"))
self.pushButton.setText(_translate("DockWidget", "确认修改"))
self.groupBox_2.setTitle(_translate("DockWidget", "完善个人信息"))
self.label_5.setText(_translate("DockWidget", "<html><head/><body><p align=\"right\">姓名</p></body></html>"))
self.label_6.setText(_translate("DockWidget", "<html><head/><body><p align=\"right\">电话号</p></body></html>"))
self.label_7.setText(_translate("DockWidget", "<html><head/><body><p align=\"right\">身份证号</p></body></html>"))
self.pushButton_2.setText(_translate("DockWidget", "确认完善"))
self.label_8.setText(_translate("DockWidget", "<html><head/><body><p align=\"right\">现住址</p></body></html>"))
self.label_9.setText(_translate("DockWidget", "<html><head/><body><p align=\"right\">出生日期</p></body></html>"))
self.label_10.setText(_translate("DockWidget", "<html><head/><body><p align=\"right\">民族</p></body></html>"))
self.label_11.setText(_translate("DockWidget", "<html><head/><body><p align=\"right\">性别</p></body></html>"))
self.label_12.setText(_translate("DockWidget", "<html><head/><body><p align=\"right\">学历</p></body></html>"))
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_()) # 启动主事件循环
执行步骤
打开数据库初始化数据库a_data_sheets/lowp.sql
运行_user/User.py文件
四、界面展示
五、文档示例
完整功能b站演示视频链接
小麦病害检测系统——本系统基于pyqt5,mysql,yolov7实现了界面友好型的小麦病害检测,包括用户、管理员注册、登录,找回,融合chatgpt实现智能助手。
本教程所涉及文件(基础版程序框架)获取点赞+收藏+关注博主后于评论区留言
本教程所涉及文件(基础版程序框架含登录功能)获取请联系qq 2591102423
本项目为本人及团队成员2023上半学年软件工程作业,完整资料包含完整代码,30000字软件设计开发文档,ppt演示,效果演示视频,获取请联系qq 1248426034