大家好,给大家分享一下python控制台程序学生信息管理系统,很多人还不知道这一点。下面详细解释一下。现在让我们来看看!
目录
一.知识点回顾 4
- python基础 4
2.tkinter库 4 - MySQL数据库 4
一. 前期准备 5 - 工具使用 5
2.数据库创建(students库) 5
① 账户信息表(verify) 5
② 学生信息表(student) 5
③ 学生成绩表(score) 5
二. 设计基本思路 6 - 登录 6
- 注册 6
- 学生端 6
- 教师端 6
三. 设计流程 7 - 登录和注册页面 8
- 学生端页面 8
- 教师端页面 8
- 学生基本信息修改页面 9
- 学生成绩录入界面 9
- 学生信息表及学生成绩表 10
- 密码修改页面 11
六.总结 11 - 心得体会 11
- Python对大数据专业的优势 11
七.核心代码 12 - 学生信息修改 12
- 学生成绩录入 14
- 学生信息删除 17
- 注册 17
一.知识点回顾
1.python基础
2.tkinter库
Python自带了tkinter 模块,实质上是一种流行的面向对象的GUI工具包 TK 的Python编程接口,提供了快速便利地创建GUI应用程序的方法。其图像化编程的基本步骤通常包括:导入 tkinter 模块,创建 GUI 根窗体,添加人机交互控件并编写相应的函数Python中Turtle画蝴蝶。在主事件循环中等待用户触发事件响应。
Tkinter的优势:相比Python的其他GUI库更加简单,跨平台,Python的标准库,不需要安装。
2.MySQL数据库
对数据统一管理,方便数据的管理与程序的调用,MySQL数据库作为一个开源的数据库,具有软件体积小,安装使用简单,并且易于维护,安装及维护成本低的特点。
数据库的优点:
1.持久化数据到本地
2.可以实现结构化查询,方便
数据库相关概念:
1、DB:数据库,保存一组有组织的数据的容器
2、DBMS:数据库管理系统,又称为数据库软件(产品),用于管理DB中的数据
3、SQL:结构化查询语言,用于和DBMS通信的
数据库存储数据的特点:
1、将数据放到表中,表再放到库中
2、一个数据库中可以有多个表,每个表都有一个的名字,用来标识自己。表名具有唯一性。
3、表具有一些特性,这些特性定义了数据在表中如何存储,类似java中 “类”的设计。
4、表由列组成,我们也称为字段。所有表都是由一个或多个列组成的,每一列类似java 中的“属性”
5、表中的数据是按行存储的,每一行类似于java中的“对象”
一.前期准备
1.工具使用
Pycharm,vscode
数据库:MySQL,SQLyog
本文转载自:http://www.biyezuopin.vip/onews.asp?id=16539
import tkinter as tk
from tkinter import ttk
import tkinter.messagebox as mb
import sqlite3
# 连接数据库
cn = sqlite3.connect('student.db')
cur = cn.cursor()
# 登录信息验证
def verify():
s1 = c1.get()
s2 = e1.get()
s3 = e2.get()
if s2 == '' or s3 == '':
y1 = mb.showinfo('登录', '请输入账户与密码')
print(y1)
else:
cur.execute('select * from verify where mold=? and name=? and password=?', (s1, s2, s3,))
lg = cur.fetchone()
if lg:
y2 = mb.showinfo('登录', '登录成功')
print(y2)
if s1 == '学生':
rt.destroy()
student(s2)
elif s1 == '教师':
rt.destroy()
teacher(s2)
else:
y3 = mb.showinfo('登录', '用户名或密码错误,请检查!')
print(y3)
return 0
# 注册页面
def login():
def close():
rt1.destroy()
def into():
s7 = var7.get()
s6 = var6.get()
s4 = c2.get()
s5 = var5.get()
if s4 == '' or s5 == '' or s6 == '' or s7 == '':
y4 = mb.showinfo('注册', '请输入账户与密码')
print(y4)
else:
if s6 == s7:
if s5.isdigit():
if 0 <= int(s5) < 100000:
cur.execute('select * from verify where name=?', (s5,))
lg = cur.fetchone()
if lg:
y6 = mb.showinfo('注册', '用户名已存在')
print(y6)
else:
if s4 == '教师':
cur.execute('insert into verify values(?,?,?)', (s5, s6, s4,))
cn.commit()
y8 = mb.showinfo('注册', '注册成功')
print(y8)
rt1.destroy()
elif s4 == '学生':
cur.execute('insert into verify values(?,?,?)', (s5, s6, s4,))
cur.execute('insert into students values(?,0 ,0 ,0 ,0 ,0 , 0)', (s5,))
cur.execute('insert into score values(?,0,0,0,0,0,0)', (s5,))
cn.commit()
print(s4 + s5 + s6)
y8 = mb.showinfo('注册', '注册成功')
print(y8)
rt1.destroy()
else:
y7 = mb.showinfo('注册', '账号格式错误')
print(y7)
else:
y8 = mb.showinfo('注册', '账号格式错误')
print(y8)
else:
y5 = mb.showinfo('注册', '两次输入密码不同')
print(y5)
rt1 = tk.Toplevel()
rt1.title("账号注册")
rt1.geometry('400x400')
rt1.update()
curx1 = rt1.winfo_width()
cury1 = rt1.winfo_height()
scnx1 = rt1.winfo_screenwidth()
scny1 = rt1.winfo_screenheight()
tm1 = '%dx%d+%d+%d' % (curx1, cury1, (scnx1 - curx1) / 2 + 400, (scny1 - cury1) / 2)
rt1.geometry(tm1)
rt1.resizable(False, False)
var4 = tk.StringVar()
c2 = ttk.Combobox(rt1, textvariable=var4, font=("宋体", 20), state='readonly')
c2['values'] = ("学生", "教师")
c2["state"] = "readonly"
c2.set("学生")
c2.current(0)
c2.place(x=40, y=40)
b14 = tk.Label(rt1, text="账号", font=("宋体", 20))
b14.place(x=40, y=100)
var5 = tk.StringVar()
e13 = tk.Entry(rt1, textvariable=var5, width=15, font=("宋体", 20))
e13.place(x=120, y=100)
b15 = tk.Label(rt1, text="密码", font=("宋体", 20))
b15.place(x=40, y=160)
var6 = tk.StringVar()
e14 = tk.Entry(rt1, textvariable=var6, width=15, font=("宋体", 20), show='*')
e14.place(x=120, y=160)
e14.focus_set()
b6 = tk.Label(rt1, text="确认密码", font=("宋体", 20))
b6.place(x=20, y=220)
var7 = tk.StringVar()
e6 = tk.Entry(rt1, textvariable=var7, width=15, font=("宋体", 20), show='*')
e6.place(x=130, y=220)
e6.focus_set()
bu3 = tk.Button(rt1, text="注册", width=7, height=1, font=("华文行楷", 20), command=lambda: into())
bu3.place(x=60, y=300)
bu4 = tk.Button(rt1, text="返回", width=7, height=1, font=("华文行楷", 20), command=lambda: close())
bu4.place(x=200, y=300)
b5 = tk.Label(rt1, text="注意:账号为学号或教师编号,由1~5位阿拉伯数字组成", font=("宋体", 10), width=45, height=2)
b5.place(x=40, y=360)
rt1.mainloop()
return 0
# 修改密码
def xiugaimima(s):
def into(s):
s1 = e1.get()
s2 = e2.get()
s3 = e3.get()
print(s)
cur.execute('select * from verify where name=?',(s,))
tm4 = cur.fetchone()
print(tm4[1])
if s1 == '' or s2 == '' or s3 == '':
y1 = mb.showinfo('密码修改', '请输入密码')
print(y1)
else:
if s2 == s3:
if s1 == tm4[1]:
cur.execute('update verify set password=? where name=?', (s2, s,))
cn.commit()
lg = cur.fetchone()
y3 = mb.showinfo('密码修改', '密码修改成功')
print(y3)
rt7.destroy()
return 1
else:
y3 = mb.showinfo('密码修改', '原密码错误')
print(y3)
else:
y2 = mb.showinfo('密码修改', '两次输入密码不同')
print(y2)
def close():
rt7.destroy()
rt7 = tk.Tk()
rt7.title("密码修改")
rt7.geometry('400x300')
rt7.update()
curx = rt7.winfo_width()
cury = rt7.winfo_height()
scnx = rt7.winfo_screenwidth()
scny = rt7.winfo_screenheight()
tm3 = '%dx%d+%d+%d' % (curx, cury, (scnx - curx) / 2, (scny - cury) / 2)
rt7.geometry(tm3)
rt7.resizable(False, False)
b1 = tk.Label(rt7, text="旧密码:", font=("宋体", 20))
b1.place(x=40, y=40)
var1 = tk.StringVar()
e1 = tk.Entry(rt7, textvariable=var1, width=15, font=("宋体", 20), show='*')
e1.place(x=160, y=40)
b2 = tk.Label(rt7, text="新密码:", font=("宋体", 20))
b2.place(x=40, y=100)
var2 = tk.StringVar()
e2 = tk.Entry(rt7, textvariable=var2, width=15, font=("宋体", 20), show='*')
e2.place(x=160, y=100)
b3 = tk.Label(rt7, text="确认密码:", font=("宋体", 20))
b3.place(x=40, y=160)
var3 = tk.StringVar()
e3 = tk.Entry(rt7, textvariable=var3, width=15, font=("宋体", 20), show='*')
e3.place(x=160, y=160)
bu3 = tk.Button(rt7, text="确定", width=7, height=1, font=("华文行楷", 20), command=lambda: into(s))
bu3.place(x=60, y=230)
bu4 = tk.Button(rt7, text="取消", width=7, height=1, font=("华文行楷", 20), command=lambda: close())
bu4.place(x=200, y=230)
rt7.mainloop()
# 学生个人信息修改
def xinxixiugei(s):
def close():
rt6.destroy()
def tijiao():
s1 = e1.get()
s2 = c2.get()
s3 = c3.get()
s4 = e4.get()
s5 = e5.get()
s6 = c6.get()
if s1 == '' or s2 == '' or s3 == '' or s4== '' or s5 == '' or s6 == '':
y2 = mb.showinfo('信息修改', '信息修改成功')
print(y2)
else:
if s5.isdigit():
if 9999999999 < int(s5) < 100000000000:
cur.execute('update students set name=?, sex=?, age=?, grade=?, phone=?, college=? where id=?', (s1,s2,s3,s4,s5,s6,s,))
cur.execute('update score set name=?, grade=? where id=?',(s1, s4, s,))
cn.commit()
y1 = mb.showinfo('信息修改', '信息修改成功')
print(y1)
rt6.destroy()
else:
y3 = mb.showinfo('信息修改', '电话号码位数错误')
print(y3)
else:
y3 = mb.showinfo('信息修改', '电话号码格式错误')
print(y3)
rt6 = tk.Tk()
rt6.title("学生个人信息修改")
rt6.geometry('500x400')
rt6.update()
curx = rt6.winfo_width()
cury = rt6.winfo_height()
scnx = rt6.winfo_screenwidth()
scny = rt6.winfo_screenheight()
tm6 = '%dx%d+%d+%d' % (curx, cury, (scnx - curx) / 2, (scny - cury) / 2)
rt6.geometry(tm6)
rt6.resizable(False, False)
cur.execute('select * from students where id=?', (s,))
tm1 = cur.fetchone()
b1 = tk.Label(rt6, text="姓名:", font=("宋体", 20))
b1.place(x=40, y=40)
var1 = tk.StringVar()
e1 = tk.Entry(rt6, textvariable=var1, width=10, font=("宋体", 20))
e1.place(x=120, y=40)
e1.insert(0,tm1[1])
b2 = tk.Label(rt6, text="性别:", font=("宋体", 20))
b2.place(x=40, y=100)
var2 = tk.StringVar()
c2 = ttk.Combobox(rt6, textvariable=var2, width=9, font=("宋体", 20))
c2['values'] = ("男", "女")
c2["state"] = "readonly"
c2.current(0)
c2.set(tm1[2])
c2.place(x=120, y=100)
b3 = tk.Label(rt6, text="年龄:", font=("宋体", 20))
b3.place(x=40, y=160)
var3 = tk.StringVar()
c3 = ttk.Combobox(rt6, textvariable=var3, width=9, font=("宋体", 20))
c3['values'] = ("17", "18", "19", "20", '21', '22', '23', '24', '25')
c3["state"] = "readonly"
c3.current(2)
c3.set(tm1[3])
c3.place(x=120, y=160)
b4 = tk.Label(rt6, text="班级:", font=("宋体", 20))
b4.place(x=40, y=220)
var4 = tk.StringVar()
e4 = tk.Entry(rt6, textvariable=var4, width=10, font=("宋体", 20))
e4.insert(0,tm1[4])
e4.place(x=120, y=220)
b5 = tk.Label(rt6, text="电话:", font=("宋体", 20))
b5.place(x=40, y=280)
var5 = tk.StringVar()
e5 = tk.Entry(rt6, textvariable=var5, width=10, font=("宋体", 20))
e5.insert(0, tm1[5])
e5.place(x=120, y=280)
b6 = tk.Label(rt6, text="学院:", font=("宋体", 20))
b6.place(x=40, y=340)
var6 = tk.StringVar()
c6 = ttk.Combobox(rt6, textvariable=var6, width=9, font=("宋体", 20))
c6['values'] = ("电子与信息工程学院", "机械工程学院", '数学学院')
c6["state"] = "readonly"
c6.current(0)
c6.set(tm1[6])
c6.place(x=120, y=340)
b7 = tk.Label(rt6, text='学号:'+tm1[0],font=('华文行楷',20))
b7.place(x=300,y=40)
bu7 = tk.Button(rt6, text="提交信息", width=16, height=1, font=("宋体", 15), command=lambda: tijiao())
bu7.place(x=300, y=100)
bu8 = tk.Button(rt6, text="退出", width=10, height=1, font=("宋体", 15), command=lambda: close())
bu8.place(x=300, y=200)
rt6.mainloop()
return 0