Python学生成绩管理系统
说明:
- 这是一个极其简易的管理系统,这是本人本科阶段的课堂作业,并无任何商业或者实用价值(因上次有人留言说我写的太烂了,特此说明!)
- 此管理系统实现了 增、删、改、查 四个功能
- 未关联任何数据库软件
- 使用CSV文件当作数据库
- 可实现数据存储功能
- 极其简易,不喜勿喷!
- <--微信在左边
最近加我微信的颇多,都是大学生应付课设
在此说明,非技术讨论者,勿扰
另外,已增加 注册功能
2018年12月17日 11点31分
运行截图:
代码:
源码在此点击打开链接
(一不小心设置了积分,网盘链接:https://pan.baidu.com/s/14kjU0FxI-eKE5IaA0A_syQ
提取码:31vl ,给个赞哈,老铁!
)
main.py
from tkinter import *
from LoginPage import *
root = Tk()
root.title('Python成绩管理系统_by vision')
LoginPage(root)
root.mainloop()
LoginPage.py
from tkinter import *
from tkinter.messagebox import *
from MainPage import *
class LoginPage(object):
def __init__(self, master=None):
self.root = master #定义内部变量root
self.root.geometry('%dx%d' % (300, 180)) #设置窗口大小
self.username = StringVar()
self.password = StringVar()
self.createPage()
def createPage(self):
self.page = Frame(self.root) #创建Frame
self.page.pack()
Label(self.page).grid(row=0, stick=W)
Label(self.page, text = '账户: ').grid(row=1, stick=W, pady=10)
Entry(self.page, textvariable=self.username).grid(row=1, column=1, stick=E)
Label(self.page, text = '密码: ').grid(row=2, stick=W, pady=10)
Entry(self.page, textvariable=self.password, show='*').grid(row=2, column=1, stick=E)
Button(self.page, text='登陆', command=self.loginCheck).grid(row=3, stick=W, pady=10)
Button(self.page, text='退出', command=self.page.quit).grid(row=3, column=1, stick=E)
def loginCheck(self):
name = self.username.get()
password = self.password.get()
if name=='admin' and password=='admin':
self.page.destroy()
MainPage(self.root)
else:
showinfo(title='错误', message='账号或密码错误!')
MainPage.py
from tkinter import *
from view import * #菜单栏对应的各个子页面
class MainPage(object):
def __init__(self, master=None):
self.root = master #定义内部变量root
self.root.geometry('%dx%d' % (600, 400)) #设置窗口大小
self.createPage()
def createPage(self):
self.inputPage = InputFrame(self.root) # 创建不同Frame
self.deletePage = DeleteFrame(self.root)
self.modifyPage = ModifyFrame(self.root)
self.queryPage = QueryFrame(self.root)
self.inputPage.pack() #默认显示数据录入界面
menubar = Menu(self.root)
menubar.add_command(label='增', command = self.inputData)
menubar.add_command(label='删', command = self.deleteData)
menubar.add_command(label='改', command = self.modifyData)
menubar.add_command(label='查', command = self.queryData)
self.root['menu'] = menubar # 设置菜单栏
def inputData(self):
self.inputPage.pack()
self.queryPage.pack_forget()
self.deletePage.pack_forget()
self.modifyPage.pack_forget()
def deleteData(self):
self.inputPage.pack_forget()
self.queryPage.pack_forget()
self.deletePage.pack()
self.modifyPage.pack_forget()
def modifyData(self):
self.inputPage.pack_forget()
self.queryPage.pack_forget()
self.deletePage.pack_forget()
self.modifyPage.pack()
def queryData(self):
self.inputPage.pack_forget()
self.queryPage.pack()
self.deletePage.pack_forget()
self.modifyPage.pack_forget()
view.py
from tkinter import *
from tkinter.messagebox import *
class InputFrame(Frame): # 继承Frame类
def __init__(self, master=None):
Frame.__init__(self, master)
self.root = master #定义内部变量root
self.E1 = Entry(self)
self.E2 = Entry(self)
self.E3 = Entry(self)
self.E4 = Entry(self)
self.E5 = Entry(self)
self.createPage()
def Isspace(self,text):
temp = 0
for i in text:
if not i.isspace():
temp = 1
break;
if temp==1:
return 0
else:
return 1
def write(self,name,num,course,score):
f = open('成绩.csv','r',encoding='utf-8')
for line in f.readlines():
info = line[:-1].split(",")
if len(info)<4:
break
if info[1]==num and info[2]==course:
messagebox.showinfo(title='结果', message ="已存在该学生科目信息!")
f.close()
return
f.close()
f = open('成绩.csv','a',encoding='utf-8')
f.write('{},{},{},{}\n'.format(name,num,course,score))
f.close()
messagebox.showinfo(title='提示', message ="写入成功")
return
def click(self):
name = self.E1.get()
num = self.E2.get()
course = self.E3.get()
score = self.E4.get()
if self.Isspace(name) or self.Isspace(num) or self.Isspace(course) or self.Isspace(score) :
messagebox.showinfo(title='提示', message ="输入项为空")
else:
self.write(name,num,course,score)
def createPage(self):
Label(self).grid(row=0, stick=W, pady=10)
Label(self, text = '姓名: ').grid(row=1, stick=W, pady=10)
self.E1.grid(row=1, column=1, stick=E)
Label(self, text = '学号: ').grid(row=2, stick=W, pady=10)
self.E2.grid(row=2, column=1, stick=E)
Label(self, text = '科目: ').grid(row=3, stick=W, pady=10)
self.E3.grid(row=3, column=1, stick=E)
Label(self, text = '成绩: ').grid(row=4, stick=W, pady=10)
self.E4.grid(row=4, column=1, stick=E)
Button(self, text='录入',command=self.click).grid(row=6, column=1, stick=E, pady=10)
class DeleteFrame(Frame): # 继承Frame类
def __init__(self, master=None):
Frame.__init__(self, master)
self.root = master #定义内部变量root
self.E1 = Entry(self)
self.E2 = Entry(self)
self.createPage()
def Isspace(self,text):
temp = 0
for i in text:
if not i.isspace():
temp = 1
break;
if temp==1:
return 0
else:
return 1
def delete(self,num,course):
temp = 0
with open("成绩.csv","r",encoding="utf-8") as f:
lines = f.readlines()
with open("成绩.csv","w",encoding="utf-8") as f_w:
for line in lines:
info = line[:-1].split(",")
if info[1]==num and info[2]==course:
temp = 1
continue
f_w.write(line)
if temp==0:
messagebox.showinfo(title='提示', message ="没有该信息")
else:
messagebox.showinfo(title='提示', message ="删除成功")
def click(self):
num = self.E1.get()
course = self.E2.get()
if self.Isspace(num) or self.Isspace(course):
messagebox.showinfo(title='提示', message ="输入项为空")
else:
self.delete(num,course)
def createPage(self):
Label(self).grid(row=0, stick=W, pady=10)
Label(self, text = '学号: ').grid(row=1, stick=W, pady=10)
self.E1.grid(row=1, column=1, stick=E)
Label(self, text = '科目: ').grid(row=2, stick=W, pady=10)
self.E2.grid(row=2, column=1, stick=E)
Button(self, text='删除',command=self.click).grid(row=6, column=1, stick=E, pady=10)
class ModifyFrame(Frame): # 继承Frame类
def __init__(self, master=None):
Frame.__init__(self, master)
self.root = master #定义内部变量root
self.E1 = Entry(self)
self.E2 = Entry(self)
self.E3 = Entry(self)
self.E4 = Entry(self)
self.E5 = Entry(self)
self.createPage()
def Isspace(self,text):
temp = 0
for i in text:
if not i.isspace():
temp = 1
break;
if temp==1:
return 0
else:
return 1
def modify(self,name,num,course,score):
temp = 0
with open("成绩.csv","r",encoding="utf-8") as f:
lines = f.readlines()
with open("成绩.csv","w",encoding="utf-8") as f_w:
for line in lines:
info = line[:-1].split(",")
if info[1]==num and info[2]==course:
temp = 1
f_w.write('{},{},{},{}\n'.format(name,num,course,score))
continue
f_w.write(line)
if temp==0:
messagebox.showinfo(title='提示', message ="没有该信息")
else:
messagebox.showinfo(title='提示', message ="修改成功")
def click(self):
name = self.E1.get()
num = self.E2.get()
course = self.E3.get()
score = self.E4.get()
if self.Isspace(name) or self.Isspace(num) or self.Isspace(course) or self.Isspace(score) :
messagebox.showinfo(title='提示', message ="输入项为空")
else:
self.modify(name,num,course,score)
def createPage(self):
Label(self).grid(row=0, stick=W, pady=10)
Label(self, text = '姓名: ').grid(row=1, stick=W, pady=10)
self.E1.grid(row=1, column=1, stick=E)
Label(self, text = '学号: ').grid(row=2, stick=W, pady=10)
self.E2.grid(row=2, column=1, stick=E)
Label(self, text = '科目: ').grid(row=3, stick=W, pady=10)
self.E3.grid(row=3, column=1, stick=E)
Label(self, text = '成绩: ').grid(row=4, stick=W, pady=10)
self.E4.grid(row=4, column=1, stick=E)
Button(self, text='修改',command=self.click).grid(row=6, column=1, stick=E, pady=10)
class QueryFrame(Frame): # 继承Frame类
def __init__(self, master=None):
Frame.__init__(self, master)
self.root = master #定义内部变量root
self.E1 = Entry(self)
self.E2 = Entry(self)
self.createPage()
def Isspace(self,text):
temp = 0
for i in text:
if not i.isspace():
temp = 1
break;
if temp==1:
return 0
else:
return 1
def query(self,num,course):
f = open('成绩.csv','r',encoding='utf-8')
for line in f.readlines():
info = line[:-1].split(",")
if info[1]==num and info[2]==course:
messagebox.showinfo(title='结果', message ="姓名:"+info[0]+"\n学号:"+info[1]+"\n科目:"+info[2]+"\n成绩:"+info[3])
f.close()
return
messagebox.showinfo(title='提示', message ="没有该信息")
f.close()
return
def click(self):
num = self.E1.get()
course = self.E2.get()
if self.Isspace(num) or self.Isspace(course):
messagebox.showinfo(title='提示', message ="输入项为空")
else:
self.query(num,course)
def createPage(self):
Label(self).grid(row=0, stick=W, pady=10)
Label(self, text = '学号: ').grid(row=1, stick=W, pady=10)
self.E1.grid(row=1, column=1, stick=E)
Label(self, text = '科目: ').grid(row=2, stick=W, pady=10)
self.E2.grid(row=2, column=1, stick=E)
Button(self, text='查找',command=self.click).grid(row=6, column=1, stick=E, pady=10)
成绩.csv
学生1,001,语文,100
学生1,001,数学,100
学生2,002,语文,80
学生2,002,数学,100
学生3,003,语文,100
(最一行不要删!!!)
代码很简单,不做分析。
来源:CSDN
作者:Vision_Tung
链接:https://blog.csdn.net/Vision_Tung/article/details/80367202