大家好,我是python222_小锋老师,最近写了一套PyQt6图书管理系统源码,附带完整开发视频教程,作为Python学习者的入门实战项目,带大家一起入门学习Python技术,感谢大家支持,特来分享下哈。
项目实战视频
PyQt6图书管理系统视频教程 Python桌面开发 Python入门级项目实战 (无废话版) 火爆连载更新中~_哔哩哔哩_bilibiliPyQt6图书管理系统视频教程 Python桌面开发 Python入门级项目实战 (无废话版) 火爆连载更新中~共计9条视频,包括:PyQt6图书管理系统视频教程 Python桌面开发 Python入门级项目实战 (无废话版) 火爆连载更新中~、第2讲 登录功能UI设计实现、第3讲 数据库操作工具包dbUtil.py封装等,UP主更多精彩视频,请关注UP账号。https://www.bilibili.com/video/BV18t4y1R7Qp/
项目介绍
本项目作为Python入门实战项目,数据库采用Mysql,操作数据采用PyMsql。项目就三个用,用户表,图书类别表,图书表。图书和图书类别实现一对多,主外键关联,通过PyQt6图形化技术,以及Python,来实现对经典多对一表之间的逻辑操作。
通过这个入门项目,带大家一起来深入体验Python项目实战开发。
系统展示
部分代码
# Form implementation generated from reading ui file '登录.ui'
#
# Created by: PyQt6 UI code generator 6.4.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.
import sys
from PyQt6 import QtCore, QtGui, QtWidgets, uic
from PyQt6.QtWidgets import QApplication, QWidget, QPushButton, QMessageBox, QLineEdit
import main
from dao import userDao
from entity.UserModel import User
class Ui_Form(QWidget):
def __init__(self):
super(Ui_Form, self).__init__()
self.setupUi(self)
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(517, 423)
self.formLayoutWidget = QtWidgets.QWidget(parent=Form)
self.formLayoutWidget.setGeometry(QtCore.QRect(100, 130, 321, 168))
self.formLayoutWidget.setObjectName("formLayoutWidget")
self.formLayout = QtWidgets.QFormLayout(self.formLayoutWidget)
self.formLayout.setContentsMargins(30, 10, 10, 0)
self.formLayout.setHorizontalSpacing(30)
self.formLayout.setVerticalSpacing(50)
self.formLayout.setObjectName("formLayout")
self.label = QtWidgets.QLabel(parent=self.formLayoutWidget)
font = QtGui.QFont()
font.setPointSize(12)
self.label.setFont(font)
self.label.setObjectName("label")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label)
self.lineEdit = QtWidgets.QLineEdit(parent=self.formLayoutWidget)
self.lineEdit.setObjectName("lineEdit")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.ItemRole.FieldRole, self.lineEdit)
self.label_2 = QtWidgets.QLabel(parent=self.formLayoutWidget)
font = QtGui.QFont()
font.setPointSize(12)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_2)
self.lineEdit_2 = QtWidgets.QLineEdit(parent=self.formLayoutWidget)
self.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.EchoMode.Password)
self.lineEdit_2.setObjectName("lineEdit_2")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.ItemRole.FieldRole, self.lineEdit_2)
self.pushButton = QtWidgets.QPushButton(parent=Form)
self.pushButton.setGeometry(QtCore.QRect(130, 280, 101, 31))
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("images/login.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
self.pushButton.setIcon(icon)
self.pushButton.setObjectName("pushButton")
# 加点击信息槽
self.pushButton.clicked.connect(self.login)
self.pushButton_2 = QtWidgets.QPushButton(parent=Form)
self.pushButton_2.setGeometry(QtCore.QRect(300, 280, 91, 31))
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap("images/reset.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
self.pushButton_2.setIcon(icon1)
self.pushButton_2.setObjectName("pushButton_2")
self.label_3 = QtWidgets.QLabel(parent=Form)
self.label_3.setGeometry(QtCore.QRect(190, 60, 221, 51))
font = QtGui.QFont()
font.setPointSize(26)
self.label_3.setFont(font)
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(parent=Form)
self.label_4.setGeometry(QtCore.QRect(120, 50, 61, 61))
self.label_4.setText("")
self.label_4.setPixmap(QtGui.QPixmap("images/logo.png"))
self.label_4.setObjectName("label_4")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "管理员登录"))
self.label.setText(_translate("Form", "用户名:"))
self.label_2.setText(_translate("Form", "密 码:"))
self.pushButton.setText(_translate("Form", "登录"))
self.pushButton_2.setText(_translate("Form", "重置"))
self.label_3.setText(_translate("Form", "图书管理系统"))
def resetForm(self):
"""
重置
:return:
"""
self.lineEdit.setText("")
self.lineEdit_2.setText("")
def login(self):
"""
用户登录判断 数据库判断成功,则打开主窗体,否则提示报错信息
:return:
"""
userName = self.lineEdit.text()
password = self.lineEdit_2.text()
if userName.strip() == "" or password.strip() == "":
QMessageBox.warning(None, '系统提示', '用户名和密码不能为空!')
else:
user = User(userName, password)
resultUser = userDao.login(user)
if resultUser:
print("用户登录成功")
userDao.currentUser = user
self.m = main.Ui_MainWindow() # 实例化主窗体
self.m.show() # 打开主窗体
self.hide() # 隐藏登录窗体
else:
print("用户登录失败")
QMessageBox.warning(None, '系统提示', '用户名或者密码输入错误!')
if __name__ == '__main__':
app = QApplication(sys.argv)
ui = Ui_Form()
ui.show()
sys.exit(app.exec())
"""
数据库连接工具
作者 : 小锋老师
官网 : www.python222.com
"""
from pymysql import Connection
def getCon():
"""
获取数据连接
:return: 数据库连接
"""
con = Connection(
host="localhost", # 主机名
port=3306, # 端口
user="root", # 账户
password="123456", # 密码
database="db_book", # 数据库
autocommit=True # 设置自动提交
)
return con
def closeCon(con: Connection):
"""
关闭数据库连接
:param con: 数据库连接
:return:
"""
if con:
con.close()
源码下载
CSDN 1积分下载:https://download.csdn.net/download/caofeng891102/88740614
或者免费领取加小锋老师wx:java3459
热门推荐
免费分享一套PyQt6学生信息管理系统 Python管理系统 Python源码,挺漂亮的-CSDN博客文章浏览阅读2.3k次,点赞82次,收藏35次。期末作业要求用Qt做一个学生管理系统,笔者这段时间在自学Python,故在征求老师同意后不用C++而选择了Python的PyQt5,本项目主要实现了PyQt5的增删改查。因为学习PyQt5的时间短,写代码时遇到了很多困难,笔者在CSDN与Github上我查阅了大量的资料,最终做了一个半成品出来。但笔者认为,以这个小项目作为一个入门练手项目十分合适,现将其分享,希望能够帮助到新手入门的人。本项目主要用到了PyQt5、pymysql、xlwt模块、Mysql数据库、QtDesigner和pyuic。https://blog.csdn.net/caoli201314/article/details/135313681