用python简单实现了一个科研管理系统的数据库大作业,有用户界面,可以实现增删改查功能
下面是6个主要模块,有需要源码的可以私信
1:连接模块 根据自己的mysql数据库输入参数即可连接
import pymysql def connect(): conn = pymysql.connect(host='localhost', user='root',password=' ',database='',autocommit=True)#连接数据库library,用户和密码按需修改 cursor = conn.cursor() return cursor, conn
2:登录模块 实现登录界面并且有三种身份,根据数据库里账号密码来判断登录是否正确
from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Login(object): def setupUi(self, Login): #登录界面 Login.setObjectName("Login") Login.setWindowModality(QtCore.Qt.ApplicationModal) Login.resize(800, 600) self.label = QtWidgets.QLabel(Login) self.label.setGeometry(QtCore.QRect(20, 20, 100, 30)) self.label.setTextFormat(QtCore.Qt.AutoText) self.label.setObjectName("label") #用户界面 self.user = QtWidgets.QLabel(Login) self.user.setGeometry(QtCore.QRect(160, 100, 60, 60)) self.user.setObjectName("user") #密码界面 self.password = QtWidgets.QLabel(Login) self.password.setGeometry(QtCore.QRect(160, 150, 60, 26)) self.password.setObjectName("password") #身份界面 self.identify = QtWidgets.QLabel(Login) self.identify.setGeometry(QtCore.QRect(140, 180, 91, 59)) self.identify.setObjectName("identify") #用户行 self.userline = QtWidgets.QLineEdit(Login) self.userline.setGeometry(QtCore.QRect(290, 100, 191, 21)) self.userline.setObjectName("userline") #密码行 self.pwline = QtWidgets.QLineEdit(Login) self.pwline.setGeometry(QtCore.QRect(290, 150, 191, 21)) self.pwline.setEchoMode(QtWidgets.QLineEdit.Password) self.pwline.setObjectName("pwline") #ID盒 self.idbox = QtWidgets.QComboBox(Login) self.idbox.setGeometry(QtCore.QRect(320, 200, 121, 22)) self.idbox.setObjectName("idbox") self.idbox.addItem("") self.idbox.addItem("") self.idbox.addItem("") #登录按钮 self.loginbt = QtWidgets.QPushButton(Login) self.loginbt.setGeometry(QtCore.QRect(250, 270, 93, 28)) self.loginbt.setObjectName("loginbt") #退出按钮 self.exitbt = QtWidgets.QPushButton(Login) self.exitbt.setGeometry(QtCore.QRect(420, 270, 93, 28)) self.exitbt.setObjectName("exitbt") self.retranslateUi(Login) QtCore.QMetaObject.connectSlotsByName(Login) def retranslateUi(self, Login): _translate = QtCore.QCoreApplication.translate Login.setWindowTitle(_translate("Login", "SCUT科研管理系统")) self.label.setText(_translate("Login", "<html><head/><body><p><span style=\" font-size:15pt;\">SCUT</span></p></body></html>")) self.user.setText(_translate("Login", "<html><head/><body><p><span style=\" font-size:10pt;\">用户</span></p></body></html>")) self.password.setText(_translate("Login", "<html><head/><body><p><span style=\" font-size:12pt;\">密码</span></p></body></html>")) self.identify.setText(_translate("Login", "<html><head/><body><p><span style=\" font-size:12pt;\">身份类型</span></p></body></html>")) self.idbox.setItemText(0, _translate("Login", "秘书")) self.idbox.setItemText(1, _translate("Login", "主任")) self.idbox.setItemText(2, _translate("Login", "科研人员")) self.loginbt.setText(_translate("Login", "登录")) self.exitbt.setText(_translate("Login", "退出"))
3:秘书模块 实现了登录成功后秘书的界面及秘书所能执行的操作
import time from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtWidgets import QTableWidgetItem,QMessageBox from connect import * import pymysql cursor,conn=connect() #连接数据库 class Ui_Reader(object): #创建UI def setupUi(self, Reader): self.loginID=self.getreaderid() Reader.setObjectName("Reader") Reader.resize(719, 742) self.readertab = QtWidgets.QTabWidget(Reader) self.readertab.setGeometry(QtCore.QRect(11, 11, 701, 721)) self.readertab.setObjectName("readertab") self.borrowbook = QtWidgets.QWidget() self.borrowbook.setObjectName("borrowbook") self.returnbookid = QtWidgets.QLineEdit(self.layoutWidget1) self.returnbookid.setObjectName("returnbookid") self.horizontalLayout_3.addWidget(self.returnbookid) self.returnbookbt = QtWidgets.QPushButton(self.layoutWidget1) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.returnbookbt.sizePolicy().hasHeightForWidth()) self.returnbookbt.setSizePolicy(sizePolicy) self.returnbookbt.setObjectName("returnbookbt") self.horizontalLayout_3.addWidget(self.returnbookbt) self.label_5.setObjectName("label_5") self.horizontalLayout_6.addWidget(self.label_5) self.author = QtWidgets.QLineEdit(self.widget) self.author.setObjectName("author") self.horizontalLayout_6.addWidget(self.author) self.verticalLayout_4.addLayout(self.horizontalLayout_6) self.horizontalLayout_7 = QtWidgets.QHBoxLayout() self.horizontalLayout_7.setObjectName("horizontalLayout_7") self.label_6 = QtWidgets.QLabel(self.widget) self.label_6.setObjectName("label_6") self.horizontalLayout_7.addWidget(self.label_6) self.type = QtWidgets.QLineEdit(self.widget) self.type.setObjectName("type") self.horizontalLayout_7.addWidget(self.type) self.verticalLayout_4.addLayout(self.horizontalLayout_7) self.horizontalLayout_8 = QtWidgets.QHBoxLayout() self.horizontalLayout_8.setObjectName("horizontalLayout_8") self.label_7 = QtWidgets.QLabel(self.widget) self.label_7.setObjectName("label_7") self.horizontalLayout_8.addWidget(self.label_7) self.press = QtWidgets.QLineEdit(self.widget) self.press.setObjectName("press") self.horizontalLayout_8.addWidget(self.press) self.verticalLayout_4.addLayout(self.horizontalLayout_8) self.horizontalLayout_9.addLayout(self.verticalLayout_4) self.verticalLayout = QtWidgets.QVBoxLayout() self.verticalLayout.setObjectName("verticalLayout") self.pushButton = QtWidgets.QPushButton(self.widget) self.pushButton.setObjectName("pushButton") self.verticalLayout.addWidget(self.pushButton) self.checkbt = QtWidgets.QPushButton(self.widget) self.checkbt.setObjectName("checkbt") self.verticalLayout.addWidget(self.checkbt) self.horizontalLayout_9.addLayout(self.verticalLayout) self.readertab.addTab(self.checkbook, "") self.userinfo = QtWidgets.QWidget() self.userinfo.setObjectName("userinfo") self.verticalLayout_9 = QtWidgets.QVBoxLayout(self.userinfo) self.verticalLayout_9.setObjectName("verticalLayout_9") self.verticalLayout_8 = QtWidgets.QVBoxLayout() self.verticalLayout_8.setObjectName("verticalLayout_8") self.horizontalLayout_14 = QtWidgets.QHBoxLayout() self.horizontalLayout_14.setObjectName("horizontalLayout_14") self.verticalLayout_7 = QtWidgets.QVBoxLayout() self.verticalLayout_7.setObjectName("verticalLayout_7") self.horizontalLayout_10 = QtWidgets.QHBoxLayout() self.horizontalLayout_10.setObjectName("horizontalLayout_10") self.label_8 = QtWidgets.QLabel(self.userinfo) self.label_8.setObjectName("label_8") self.horizontalLayout_10.addWidget(self.label_8) self.lineEdit_8 = QtWidgets.QLineEdit(self.userinfo) self.lineEdit_8.setObjectName("lineEdit_8") self.horizontalLayout_10.addWidget(self.lineEdit_8) self.verticalLayout_7.addLayout(self.horizontalLayout_10) self.horizontalLayout_11 = QtWidgets.QHBoxLayout() self.horizontalLayout_11.setObjectName("horizontalLayout_11") self.label_9 = QtWidgets.QLabel(self.userinfo) self.label_9.setObjectName("label_9") self.horizontalLayout_11.addWidget(self.label_9) self.lineEdit_9 = QtWidgets.QLineEdit(self.userinfo) self.lineEdit_9.setObjectName("lineEdit_9") self.horizontalLayout_11.addWidget(self.lineEdit_9) self.verticalLayout_7.addLayout(self.horizontalLayout_11) self.horizontalLayout_12 = QtWidgets.QHBoxLayout() self.horizontalLayout_12.setObjectName("horizontalLayout_12") self.verticalLayout_7.addLayout(self.horizontalLayout_12) self.horizontalLayout_13 = QtWidgets.QHBoxLayout() self.horizontalLayout_13.setObjectName("horizontalLayout_13") self.label_11 = QtWidgets.QLabel(self.userinfo) self.label_11.setObjectName("label_11") self.horizontalLayout_13.addWidget(self.label_11) self.lineEdit_11 = QtWidgets.QLineEdit(self.userinfo) self.lineEdit_11.setObjectName("lineEdit_11") self.horizontalLayout_13.addWidget(self.lineEdit_11) self.verticalLayout_7.addLayout(self.horizontalLayout_13) self.horizontalLayout_14.addLayout(self.verticalLayout_7) self.pushButton_5 = QtWidgets.QPushButton(self.userinfo) self.pushButton_5.setObjectName("pushButton_5") self.horizontalLayout_14.addWidget(self.pushButton_5) self.verticalLayout_8.addLayout(self.horizontalLayout_14) self.textBrowser_2 = QtWidgets.QTextBrowser(self.userinfo) self.textBrowser_2.setObjectName("textBrowser_2") self.verticalLayout_8.addWidget(self.textBrowser_2) self.verticalLayout_9.addLayout(self.verticalLayout_8) self.readertab.addTab(self.userinfo, "") self.pay_2 = QtWidgets.QWidget() self.pay_2.setObjectName("pay_2") self.gridLayout = QtWidgets.QGridLayout(self.pay_2) self.gridLayout.setObjectName("gridLayout") self.money = QtWidgets.QLabel(self.pay_2) self.money.setText("") self.money.setObjectName("money") self.gridLayout.addWidget(self.money, 0, 1, 1, 1) self.label_12 = QtWidgets.QLabel(self.pay_2) self.label_12.setObjectName("label_12") self.gridLayout.addWidget(self.label_12, 0, 0, 1, 1) self.alipay = QtWidgets.QPushButton(self.pay_2) self.alipay.setObjectName("alipay") self.gridLayout.addWidget(self.alipay, 1, 2, 1, 1) self.wepay = QtWidgets.QPushButton(self.pay_2) self.wepay.setObjectName("wepay") self.gridLayout.addWidget(self.wepay, 1, 1, 1, 1) self.readertab.addTab(self.pay_2, "") self.retranslateUi(Reader) self.getreaderinfo() # self.textBrowser_2.setText(self.readerlogin self.readertab.setCurrentIndex(0) QtCore.QMetaObject.connectSlotsByName(Reader) self.borrowcheckbt.clicked.connect(self.borrowidcheck) self.borrowokbt.clicked.connect(self.submit) self.returnbookbt.clicked.connect(self.ReturnBook) self.pushButton.clicked.connect(self.selectallbook) self.checkbt.clicked.connect(self.selectbook) self.pushButton_5.clicked.connect(self.alterinfo) self.wepay.clicked.connect(self.paymoney) self.alipay.clicked.connect(self.paymoney) def retranslateUi(self, Reader): _translate = QtCore.QCoreApplication.translate Reader.setWindowTitle(_translate("Reader", "读者系统")) self.label.setText(_translate("Reader", "秘书个人信息")) self.borrowcheckbt.setText(_translate("Reader", "查询")) item = self.borrowtable.verticalHeaderItem(0) item.setText(_translate("Reader", "1")) item = self.borrowtable.horizontalHeaderItem(0) item.setText(_translate("Reader", "秘书姓名")) item = self.borrowtable.horizontalHeaderItem(1) item.setText(_translate("Reader", "秘书工号")) item = self.borrowtable.horizontalHeaderItem(2) item.setText(_translate("Reader", "秘书性别")) item = self.borrowtable.horizontalHeaderItem(3) item.setText(_translate("Reader", "秘书归属实验室")) item = self.borrowtable.horizontalHeaderItem(4) item.setText(_translate("Reader", "")) self.borrowokbt.setText(_translate("Reader", "末尾分界线")) self.readertab.setTabText(self.readertab.indexOf(self.borrowbook), _translate("Reader", "秘书信息查询")) #2 self.returnbo.setText(_translate("Reader", "修改")) self.returnbookbt.setText(_translate("Reader", "确定")) self.readertab.setTabText(self.readertab.indexOf(self.returnbook), _translate("Reader", "修改秘书信息")) #3 item = self.tableWidget.horizontalHeaderItem(0) item.setText(_translate("Reader", "秘书姓名")) item = self.tableWidget.horizontalHeaderItem(1) item.setText(_translate("Reader", "秘书工号")) item = self.tableWidget.horizontalHeaderItem(2) item.setText(_translate("Reader", "秘书性别")) item = self.tableWidget.horizontalHeaderItem(3) item.setText(_translate("Reader", "秘书归属实验室")) item = self.tableWidget.horizontalHeaderItem(4) item.setText(_translate("Reader", "")) self.label_3.setText(_translate("Reader", "秘书姓名")) self.label_4.setText(_translate("Reader", "秘书工号")) self.label_5.setText(_translate("Reader", "秘书性别")) self.label_6.setText(_translate("Reader", "秘书归属实验室")) self.label_7.setText(_translate("Reader", "")) self.pushButton.setText(_translate("Reader", "增加秘书信息")) self.checkbt.setText(_translate("Reader", "查询添加后的结果")) self.readertab.setTabText(self.readertab.indexOf(self.checkbook), _translate("Reader", "增加秘书信息")) #4 self.label_8.setText(_translate("Reader", "秘书姓名")) self.label_9.setText(_translate("Reader", "秘书性别")) self.label_11.setText(_translate("Reader", "")) self.pushButton_5.setText(_translate("Reader", "删除")) self.readertab.setTabText(self.readertab.indexOf(self.userinfo), _translate("Reader", "删除秘书信息")) #5 self.label_12.setText(_translate("Reader", "科研成果")) self.alipay.setText(_translate("Reader", "论文")) self.wepay.setText(_translate("Reader", "专利")) self.readertab.setTabText(self.readertab.indexOf(self.pay_2), _translate("Reader", "查询秘书科研成果")) ##### #第一个界面的查询 def borrowidcheck(self): bookin=self.borrowbookid.text() sql='select * from secreatry' res = cursor.execute(sql) display=cursor.fetchall() print(display) # def getreaderid(self): nowtime = time.strftime("%Y-%m-%d", time.localtime()) sql='SELECT * FROM secreatry' cursor.execute(sql) # def getreaderinfo(self): sql='SELECT * FROM secreatry ' cursor.execute(sql) readerlogined=cursor.fetchall() #第二个界面 def submit(self): sql = 'update secreatry set selab="b8-123" where saname="张三"' if sql: res = cursor.execute(sql) conn.commit() QMessageBox.warning(self, "提示", "修改成功!", QMessageBox.Yes) #修改 def ReturnBook(self): bookid = self.returnbookid.text() sql='SELECT * FROM secreatry' res=cursor.execute(sql) if res: sql = 'update secreatry set selab="b8-802" where sename="张三"' res = cursor.execute(sql) borrowinfo = cursor.fetchall() if res: print(borrowinfo) cursor.execute(sql) conn.commit() QMessageBox.warning(self, "提示", "修改成功!", QMessageBox.Yes) else: QMessageBox.warning(self, "警告", "修改信息有误 请重新输入!", QMessageBox.Yes) #第三个查询 def selectallbook(self): sql='insert into secreatry values("汤德佑","33","男","b8-234")' cursor.execute(sql) if sql: QMessageBox.warning(self, "提示", "添加成功!", QMessageBox.Yes) books=cursor.fetchall() conn.commit() #查询书籍 def selectbook(self): sql='SELECT * FROM secreatry' res=cursor.execute(sql) display = cursor.fetchall() print(display) #第四个修改 def alterinfo(self): sql = 'delete from secreatry where sename="汤德佑"' if sql: cursor.execute(sql) result=cursor.fetchall() conn.commit() QMessageBox.warning(self, "警告", "删除成功", QMessageBox.Yes) #第五个支付 def paymoney(self): money=0.00 sql = 'select * from paper' cursor.execute(sql) res=cursor.fetchall() print(res) conn.commit() self.getreaderinfo()
4:主任模块 实现了登录后的主任界面及主任的各个功能
from PyQt5 import QtCore, QtGui, QtWidgets from connect import * from PyQt5.QtWidgets import QTableWidgetItem, QMessageBox import datetime import time cursor, conn = connect() class Ui_bookadmin(object): def __init__(self): self.dibeingtime = NotImplemented self.renqi=NotImplemented self.manangedlab=NotImplemented def setupUi(self, bookadmin): bookadmin.setObjectName("bookadmin") bookadmin.resize(846, 796) self.tabWidget = QtWidgets.QTabWidget(bookadmin) self.tabWidget.setGeometry(QtCore.QRect(20, 20, 811, 761)) self.tabWidget.setObjectName("tabWidget") self.tab = QtWidgets.QWidget() self.tab.setObjectName("tab") self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.tab) self.verticalLayout_2.setObjectName("verticalLayout_2") self.verticalLayout = QtWidgets.QVBoxLayout() self.verticalLayout.setObjectName("verticalLayout") self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.label_2 = QtWidgets.QLabel(self.tab) self.label_2.setObjectName("label_2") self.horizontalLayout.addWidget(self.label_2) self.readerid = QtWidgets.QLineEdit(self.tab) self.readerid.setObjectName("dibeingtime") self.horizontalLayout.addWidget(self.readerid) self.label = QtWidgets.QLabel(self.tab) self.label.setObjectName("label") self.horizontalLayout.addWidget(self.label) self.readername = QtWidgets.QLineEdit(self.tab) self.readername.setObjectName("renqi") self.horizontalLayout.addWidget(self.readername) self.label_3 = QtWidgets.QLabel(self.tab) self.label_3.setObjectName("label_3") self.horizontalLayout.addWidget(self.label_3) self.unit = QtWidgets.QLineEdit(self.tab) self.unit.setObjectName("unit") self.horizontalLayout.addWidget(self.unit) self.verticalLayout.addLayout(self.horizontalLayout) self.horizontalLayout_2 = QtWidgets.QHBoxLayout() self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.select = QtWidgets.QPushButton(self.tab) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.select.sizePolicy().hasHeightForWidth()) self.select.setSizePolicy(sizePolicy) self.select.setObjectName("select") self.horizontalLayout_2.addWidget(self.select) self.selectall = QtWidgets.QPushButton(self.tab) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.selectall.sizePolicy().hasHeightForWidth()) self.selectall.setSizePolicy(sizePolicy) self.selectall.setObjectName("selectall") self.horizontalLayout_2.addWidget(self.selectall) self.verticalLayout.addLayout(self.horizontalLayout_2) self.readerinfors = QtWidgets.QTableWidget(self.tab) self.readerinfors.setObjectName("directorinfo") self.readerinfors.setColumnCount(8) self.readerinfors.setRowCount(0) item = QtWidgets.QTableWidgetItem() self.readerinfors.setHorizontalHeaderItem(0, item) item = QtWidgets.QTableWidgetItem() self.readerinfors.setHorizontalHeaderItem(1, item) item = QtWidgets.QTableWidgetItem() self.readerinfors.setHorizontalHeaderItem(2, item) item = QtWidgets.QTableWidgetItem() self.readerinfors.setHorizontalHeaderItem(3, item) item = QtWidgets.QTableWidgetItem() self.readerinfors.setHorizontalHeaderItem(4, item) item = QtWidgets.QTableWidgetItem() self.readerinfors.setHorizontalHeaderItem(5, item) item = QtWidgets.QTableWidgetItem() self.readerinfors.setHorizontalHeaderItem(6, item) item = QtWidgets.QTableWidgetItem() self.readerinfors.setHorizontalHeaderItem(7, item) self.verticalLayout.addWidget(self.readerinfors) self.verticalLayout_2.addLayout(self.verticalLayout) self.tabWidget.addTab(self.tab, "") self.tab_2 = QtWidgets.QWidget() self.tab_2.setObjectName("tab_2") self.verticalLayout_5 = QtWidgets.QVBoxLayout(self.tab_2) self.verticalLayout_5.setObjectName("verticalLayout_5") self.verticalLayout_3 = QtWidgets.QVBoxLayout() self.verticalLayout_3.setObjectName("verticalLayout_3") self.horizontalLayout_13 = QtWidgets.QHBoxLayout() self.horizontalLayout_13.setObjectName("horizontalLayout_13") self.horizontalLayout_3 = QtWidgets.QHBoxLayout() self.horizontalLayout_3.setObjectName("horizontalLayout_3") self.label_4 = QtWidgets.QLabel(self.tab_2) self.label_4.setObjectName("label_4") self.horizontalLayout_3.addWidget(self.label_4) self.bookid = QtWidgets.QLineEdit(self.tab_2) self.bookid.setObjectName("bookid") self.horizontalLayout_3.addWidget(self.bookid)
5:科研人员模块 实现了登录后的科研人员界面及科研的各个ca
import pymysql from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtWidgets import QTableWidgetItem,QMessageBox from connect import * from PyQt5 import QtCore, QtGui, QtWidgets cursor,conn=connect() class Ui_systemadmin(object): def __init__(self): self.conn = None def setupUi(self, systemadmin): systemadmin.setObjectName("systemadmin") systemadmin.resize(738, 747) self.tabWidget = QtWidgets.QTabWidget(systemadmin) self.tabWidget.setGeometry(QtCore.QRect(9, 9, 721, 731)) self.tabWidget.setObjectName("tabWidget") self.tab = QtWidgets.QWidget() self.tab.setObjectName("tab") self.widget = QtWidgets.QWidget(self.tab) self.widget.setGeometry(QtCore.QRect(10, 10, 701, 691)) self.widget.setObjectName("widget") self.verticalLayout = QtWidgets.QVBoxLayout(self.widget) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setObjectName("verticalLayout") self.horizontalLayout_7 = QtWidgets.QHBoxLayout() self.horizontalLayout_7.setObjectName("horizontalLayout_7") self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.label = QtWidgets.QLabel(self.widget) self.label.setObjectName("label") self.horizontalLayout.addWidget(self.label) self.readerid = QtWidgets.QLineEdit(self.widget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.readerid.sizePolicy().hasHeightForWidth()) self.readerid.setSizePolicy(sizePolicy) self.readerid.setObjectName("readerid") self.horizontalLayout.addWidget(self.readerid) self.horizontalLayout_7.addLayout(self.horizontalLayout) self.horizontalLayout_2 = QtWidgets.QHBoxLayout() self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.label_2 = QtWidgets.QLabel(self.widget) self.label_2.setObjectName("label_2") self.horizontalLayout_2.addWidget(self.label_2) self.readname = QtWidgets.QLineEdit(self.widget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.readname.sizePolicy().hasHeightForWidth()) self.readname.setSizePolicy(sizePolicy) self.readname.setObjectName("readname") self.horizontalLayout_2.addWidget(self.readname) self.horizontalLayout_7.addLayout(self.horizontalLayout_2) self.horizontalLayout_5 = QtWidgets.QHBoxLayout() self.horizontalLayout_5.setObjectName("horizontalLayout_5") self.label_4 = QtWidgets.QLabel(self.widget) self.label_4.setObjectName("label_4") self.horizontalLayout_5.addWidget(self.label_4) self.unit = QtWidgets.QComboBox(self.widget) self.unit.setObjectName("unit") self.unit.addItem("") self.unit.addItem("") self.unit.addItem("") self.unit.addItem("") self.horizontalLayout_5.addWidget(self.unit) self.horizontalLayout_7.addLayout(self.horizontalLayout_5) self.horizontalLayout_4 = QtWidgets.QHBoxLayout() self.horizontalLayout_4.setObjectName("horizontalLayout_4") self.label_3 = QtWidgets.QLabel(self.widget) self.label_3.setObjectName("label_3") self.horizontalLayout_4.addWidget(self.label_3) self.sex = QtWidgets.QComboBox(self.widget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.sex.sizePolicy().hasHeightForWidth()) self.sex.setSizePolicy(sizePolicy) self.sex.setObjectName("sex") self.sex.addItem("") self.sex.addItem("") self.horizontalLayout_4.addWidget(self.sex) self.horizontalLayout_7.addLayout(self.horizontalLayout_4) self.verticalLayout.addLayout(self.horizontalLayout_7) self.horizontalLayout_13 = QtWidgets.QHBoxLayout() self.horizontalLayout_13.setObjectName("horizontalLayout_13") self.horizontalLayout_9 = QtWidgets.QHBoxLayout() self.horizontalLayout_9.setObjectName("horizontalLayout_9") self.label_6 = QtWidgets.QLabel(self.widget) self.label_6.setObjectName("label_6") self.horizontalLayout_9.addWidget(self.label_6) self.readtype = QtWidgets.QComboBox(self.widget) self.readtype.setObjectName("readtype") self.readtype.addItem("") self.readtype.addItem("") self.readtype.addItem("") self.horizontalLayout_9.addWidget(self.readtype) self.horizontalLayout_13.addLayout(self.horizontalLayout_9) self.horizontalLayout_10 = QtWidgets.QHBoxLayout() self.horizontalLayout_10.setObjectName("horizontalLayout_10") self.label_7 = QtWidgets.QLabel(self.widget) self.label_7.setObjectName("label_7") self.horizontalLayout_10.addWidget(self.label_7) self.totalnumber = QtWidgets.QLineEdit(self.widget) self.totalnumber.setObjectName("totalnumber") self.horizontalLayout_10.addWidget(self.totalnumber) self.horizontalLayout_13.addLayout(self.horizontalLayout_10) self.horizontalLayout_11 = QtWidgets.QHBoxLayout() self.horizontalLayout_11.setObjectName("horizontalLayout_11") self.label_8 = QtWidgets.QLabel(self.widget) self.label_8.setObjectName("label_8") self.horizontalLayout_11.addWidget(self.label_8) self.number = QtWidgets.QLineEdit(self.widget) self.number.setObjectName("number") self.horizontalLayout_11.addWidget(self.number) self.horizontalLayout_13.addLayout(self.horizontalLayout_11) self.horizontalLayout_12 = QtWidgets.QHBoxLayout() self.horizontalLayout_12.setObjectName("horizontalLayout_12") self.label_9 = QtWidgets.QLabel(self.widget) self.label_9.setObjectName("label_9") self.horizontalLayout_12.addWidget(self.label_9) self.money = QtWidgets.QLineEdit(self.widget) self.money.setObjectName("money") self.horizontalLayout_12.addWidget(self.money) self.horizontalLayout_13.addLayout(self.horizontalLayout_12) self.verticalLayout.addLayout(self.horizontalLayout_13) self.horizontalLayout_8 = QtWidgets.QHBoxLayout() self.horizontalLayout_8.setObjectName("horizontalLayout_8") self.addr = QtWidgets.QPushButton(self.widget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.addr.sizePolicy().hasHeightForWidth()) self.addr.setSizePolicy(sizePolicy) self.addr.setObjectName("addr") self.horizontalLayout_8.addWidget(self.addr) self.alterr = QtWidgets.QPushButton(self.widget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.alterr.sizePolicy().hasHeightForWidth()) self.alterr.setSizePolicy(sizePolicy) self.alterr.setObjectName("alterr") self.horizontalLayout_8.addWidget(self.alterr) self.deleter = QtWidgets.QPushButton(self.widget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0)
6:主函数模块 最后执行的模块 调用其他模块
import sys import pymysql import time from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtWidgets import QApplication, QMainWindow,QMessageBox from login import Ui_Login from secreatry import Ui_Reader from connect import * from repeople import Ui_systemadmin from director import Ui_bookadmin cursor,conn=connect() class Readerui(QtWidgets.QMainWindow, Ui_Reader): def __init__(self, parent=None): super(Readerui,self).__init__(parent) self.setupUi(self) class bookadminui(QtWidgets.QMainWindow,Ui_bookadmin): def __init__(self, parent=None): super(bookadminui, self).__init__(parent) self.setupUi(self) class sysadminui(QtWidgets.QMainWindow,Ui_systemadmin): def __init__(self, parent=None): super(sysadminui, self).__init__(parent) self.setupUi(self) class MyMainForm(QMainWindow, Ui_Login): def __init__(self, parent=None): super(MyMainForm, self).__init__(parent) self.setupUi(self) self.exitbt.clicked.connect(self.exit) self.loginbt.clicked.connect(self.login) def exit(self): #退出 rec_code=QMessageBox.question(self, "确认", "好好想想真的要退出吗??", QMessageBox.Yes | QMessageBox.No) if rec_code != 65536: self.close() def login(self): #登陆 ID=self.userline.text() PW=self.pwline.text() if ID=='' or PW=='': QMessageBox.warning(self, "警告", "用户名和密码都要输入噢!!!", QMessageBox.Yes) else: if self.idbox.currentText()=='秘书': type='秘书' sql = 'select * from secreatry where sename = "%s" and seworknum="%s" '% (ID, PW) res = cursor.execute(sql) if res: self.read = Readerui() self.read.show() else: QMessageBox.warning(self, "警告", "密码错误,请重新输入!", QMessageBox.Yes) elif self.idbox.currentText()=='主任': type='主任'