引言
本课程设计使用数据库,熟悉了Python语言操作数据库,对数据库的增删改查,实现Qt designer界面设计以及excel表格的读写,代码通俗易懂,方便对所学知识的掌握。
需求分析
用类对学生成绩、代码封装使得操作使用简单;
利用数据库,增加了操作大量数据的效率,便于增删改查;
将信息读取数据库,更新后写入数据库,及时备份;
界面设计,可以在实际中直接应用此项目。
熟悉了对于界面的背景设计、字体、空间颜色、美化风格等的设计,使界面使用更直观。
概要设计
数据库的使用
使用PyMySQL模块操作数据库对数据进行存取
先安装PyMySQL模块:pip install PyMySQL,再使用时直接导入即可:import pymysql
将存放学生成绩的excel表格导入到数据库中。
安装数据库
本机安装了数据库(使用数据库操作方便快捷,若没有安装数据库,本课程设计可以使用excel表格存储查找,同样也可以。并且在使用数据库时,确保数据库是打开的,在电脑-服务-查看)
新建数据库
create database student_score; 在数据库中新建了存放学生成绩的表格和存放教师登陆信息的表格。
使用数据库
use database ***
在数据库中创建表格create table ***,可以使用命令行也可以在数据库软件中直接创建,代码中创建也可以。多种方式自选
CREATE TABLE IF NOT EXISTS teacher_login(
username varchar(32) NOT NULL,
password varchar(32) NOT NULL
读取excel表格内容
excel数据存入到数据库的表格中

将存放学生成绩信息的数据存入到数据库的表格中

在数据库中可以查看到数据存放成功了

详细设计
本部分主要分为三个界面类
教师登陆界面
登陆界面中需要查看数据库中教师的信息是否存在,密码是否正确,并给出对应的提示
登陆代码

显示界面



教师注册界面
教师注册界面将注册信息存放到数据库中,对于注册输入的信息给出响应的提示

在数据库中查看注册信息是否导入

效果



教师操作界面

对学生的成绩信息进行操作,可以增添、修改、查询、删除、导出
特别注意的是,增添信息后,数据库和界面表格中的信息都要有同样的操作,显示界面要实时刷新!!
增添信息


注意数据库和界面表格中的信息都要更新
修改信息



查询信息


若学号不存在,则查询失败

删除信息

删除失败

删除成功,数据库与界面表格中的数据都不存在了。
导出信息

提示

默认写入成功到当前运行的文件夹,文件名为当前的时间,可以根据需要修改

总结与分析
用了两周的业余时间写出了这么一个课程设计,肯定还有一些瑕疵,欢迎交流。