需要全部源码滴滴我 一:运行效果图(Login,Register,Topup,Drop user,Usermessage)
二:登陆界面源码 下面展示一些 内联代码片 。
// A code block
var foo = 'bar';
import sys
import sqlite3
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import qdarkstyle
import registerUI
import manageUI
from PyQt5.QtSql import *
class SignInWidget(QWidget):
def __init__(self):
super(SignInWidget, self).__init__()
self.resize(900, 600)
self.setWindowTitle("公交卡管理系统--登录界面")
self.setUpUI()
def setUpUI(self):
self.setWindowIcon(QIcon("D:/xiaohuangren"))
self.Vlayout = QVBoxLayout(self)
self.Hlayout1 = QHBoxLayout()
self.Hlayout2 = QHBoxLayout()
self.formlayout = QFormLayout()
self.label1 = QLabel("卡ID: ")
labelFont = QFont()
labelFont.setPixelSize(18)
lineEditFont = QFont()
lineEditFont.setPixelSize(16)
self.label1.setFont(labelFont)
self.label1.setStyleSheet("color:black")
self.label1.setStyleSheet("background-color:gold")
self.lineEdit1 = QLineEdit()
self.lineEdit1.setFixedHeight(32)
self.lineEdit1.setFixedWidth(180)
self.lineEdit1.setFont(lineEditFont)
#self.lineEdit1.setMaxLength(10)
self.formlayout.addRow(self.label1, self.lineEdit1)
self.label2 = QLabel("密码: ")
self.label2.setFont(labelFont)
self.lineEdit2 = QLineEdit()
self.label2.setStyleSheet("color:black")
self.label2.setStyleSheet("background-color:gold")
self.lineEdit2.setFixedHeight(32)
self.lineEdit2.setFixedWidth(180)
self.lineEdit2.setMaxLength(16)
passwordFont = QFont()
passwordFont.setPixelSize(9)
self.lineEdit2.setFont(passwordFont)
self.lineEdit2.setEchoMode(QLineEdit.Password)
self.formlayout.addRow(self.label2, self.lineEdit2)
self.signIn = QPushButton("登 录")
self.signIn.clicked.connect(self.signInCheck)
self.signIn.setFixedWidth(80)
self.signIn.setFixedHeight(30)
self.signIn.setFont(labelFont)
self.formlayout.addRow("", self.signIn)
self.register=QPushButton('注册')
self.register.setFixedWidth(80)
self.register.setFixedHeight(30)
self.register.setFont(labelFont)
self.formlayout.addRow('',self.register)
self.label = QLabel(" 欢迎登录公交卡管理系统!")
fontlabel = QFont()
fontlabel.setPixelSize(35)
self.label.setFixedWidth(500)
self.label.setFixedHeight(120)
self.label.setFont(fontlabel)
self.Hlayout1.addWidget(self.label, Qt.AlignCenter)
self.widget1 = QWidget()
self.widget1.setLayout(self.Hlayout1)
self.widget2 = QWidget()
self.widget2.setFixedWidth(300)
self.widget2.setFixedHeight(150)
self.widget2.setLayout(self.formlayout)
self.Hlayout2.addWidget(self.widget2, Qt.AlignCenter)
self.widget = QWidget()
self.widget.setLayout(self.Hlayout2)
self.Vlayout.addWidget(self.widget1)
self.Vlayout.addWidget(self.widget, Qt.AlignTop)
#给Button绑定信号
self.register.clicked.connect(self.turnregister)
def turnregister(self):
self.registerui=registerUI.registerui()
self.registerui.show()
def signInCheck(self):
inputcardid = self.lineEdit1.text()
inputpassword = self.lineEdit2.text()
if (inputcardid == "" or inputpassword == ""):
print(QMessageBox.warning(self, "警告", "学号和密码不可为空!", QMessageBox.Yes, QMessageBox.Yes))
return
# 打开数据库连接
db = QSqlDatabase.addDatabase("QSQLITE")
db.setDatabaseName('test.db')
db.open()
query1 = QSqlQuery()
sql1 = "SELECT * FROM Usermessage WHERE CardID='%s'" % (inputcardid)
query1.exec_(sql1)
db.close()
if (not query1.next()):
print(QMessageBox.information(self, "提示", "该账号不存在!", QMessageBox.Yes, QMessageBox.Yes))
else:
if "20210001" == inputcardid:
if inputpassword == "123456":
print(1)
self.manageui = manageUI.AdminHome()
self.close()
self.manageui.show()
else:
print(QMessageBox.warning(self, "提示", "密码错误!", QMessageBox.Yes, QMessageBox.Yes))
else:
db = QSqlDatabase.addDatabase("QSQLITE")
db.setDatabaseName('test.db')
db.open()
query2 = QSqlQuery()
sql2 = "SELECT * FROM Usermessage WHERE Password='%s'" % (inputpassword)
query2.exec_(sql2)
db.close()
if (not query2.next()):
print(QMessageBox.information(self, "提示", "密码错误!", QMessageBox.Yes, QMessageBox.Yes))
else:
print(QMessageBox.information(self, "提示", "您不是管理员用户,无法登录该系统!", QMessageBox.Yes, QMessageBox.Yes))
return
#设置背景图片
def paintEvent(self, event):
painter = QPainter(self)
pixmap = QPixmap("D:/公交背景图片/公交车4.jpg")
# 绘制窗口背景,平铺到整个窗口,随着窗口改变而改变
painter.drawPixmap(self.rect(), pixmap)
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setWindowIcon(QIcon("./images/MainWindow_1.png"))
# app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
mainMindow = SignInWidget()
mainMindow.show()
sys.exit(app.exec_())
|