python学生成绩管理系统
建立一个单机版有GUI界面的(或Web版)的学生成绩系统,能从文件(或数据库)中读写数据,并具有以下功能。
(1) 能输入并显示学生信息,并生成有关报表文件;
(2) 能将学生信息存储在数据库中,
(3) 能从数据库中读出学生信息;
(4) 能对学生信息进行增、删、改、查;
(5) 能计算学生的总分和各门功课的平均分;
(6) 能对学生信息进行排序;
(7) 能得到排序后的报表文件。
def createWidgets(self): #对象方法:创建子组件
Label(self.root, text='欢迎使用学生成绩管理系统', font=('', '12', 'bold')).place(x=160, y=50)
self.account=StringVar()
self.pass1=StringVar()
self.lblAccount = Label(self.root, text='用 户 名:') #创建Label组件-用户名
self.lblPass1 = Label(self.root, text='密 码:') #创建Label组件-密码
self.lblAccount.place(x=130, y=100) #设置Account标签位置
self.lblPass1.place(x=130,y=140) #设置密码标签位置
self.entryAccount = Entry(self.root,textvariable=self.account) #创建Entry组件
self.entryPass1 = Entry(self.root, show='*',textvariable=self.pass1) #密码默认显示为*
self.entryAccount.place(x=200,y=100) #设置用户名文本框位置
self.entryPass1.place(x=200,y=140) #设置密码文本框位置
self.identity=StringVar()
self.identity.set('T')
Radiobutton(self.root, text='教师', value='T', variable=self.identity).place(x=200, y=175)
Radiobutton(self.root, text='学生', value='S', variable=self.identity).place(x=290, y=175)
self.btnOk = Button(self.root, text='登录',width='6',command=self.funcOK) #创建按钮组件
self.btnOk.place(x=200,y=210)
self.btnCancel = Button(self.root, text='重置',width='6',command=self.fnreset) #创建按钮组件
self.btnCancel.place(x=290,y=210) #取消按钮
self.btnRegister = Button(self.root, text='注册', width='19',command=self.fnregister)
self.btnRegister.place(x=200,y=245)
ef createWidgets(self): #对象方法:创建子组件
Label(self.root, text='注册', font=('', '12', 'bold')).place(x=240, y=50)
self.Account=StringVar()
self.Pass1=StringVar()
self.Pass2=StringVar()
self.lblAccount = Label(self.root, text='用 户 名:') #创建Label组件-用户名
self.lblPass1 = Label(self.root, text='密 码:') #创建Label组件-密码
self.lblPass2=Label(self.root,text='确定密码:') #创建Label组件-确定密码
self.lblAccount.place(x=130, y=100) #设置Account标签位置
self.lblPass1.place(x=130,y=140) #设置密码标签位置
self.lblPass2.place(x=130,y=180) #设置密码标签位置
self.entryAccount = Entry(self.root, textvariable=self.Account) #创建Entry组件
self.entryPass1 = Entry(self.root, show='*', textvariable=self.Pass1) #密码默认显示为*
self.entryPass2 = Entry(self.root, show='*', textvariable=self.Pass2) # 确定密码默认显示为*
self.textDesc = Text(self.root, width=20, height=5) #创建Text组件
self.entryAccount.place(x=200,y=100) #设置用户名文本框位置
self.entryPass1.place(x=200,y=140) #设置密码文本框位置
self.entryPass2.place(x=200,y=180)
self.identity=StringVar()
self.identity.set('T')
Radiobutton(self.root, text='教师', value='T', variable=self.identity).place(x=200, y=215)
Radiobutton(self.root, text='学生', value='S', variable=self.identity).place(x=290, y=215)
self.btnOk = Button(self.root, text='立即注册', width='19', command=self.fnOK) #创建按钮组件
self.btnOk.place(x=200,y=245)
self.btncancle = Button(self.root, text='取消', width='19', command=self.fncancle) # 创建按钮组件
self.btncancle.place(x=200, y=285)
def mainInterface(self):
Label(self.root, text='学生成绩管理系统', font=('宋体', 15, 'bold')).pack()
self.logout = Label(self.root, text='注销', font=('宋体', '10', 'underline'))
self.logout.place(x=740, y=25)
self.logout.configure(cursor="hand2")
self.logout.bind('<Button-1>', func=self.fnlogout) #注销操纵
welcome=self.account+',欢迎您^V^'
Label(self.root,text=welcome,font=('宋体','12','bold')).place(x=20,y=65)
#查询
self.find=StringVar() #查询框变量
self.entrySearch=Entry(self.root,textvariable=self.find) #创建查询框Entry组件
self.btnSearch=Button(self.root, text='查询', height='1', width='5', command=self.fnsearch) #创建按钮组件
self.entrySearch.place(x=450, y=65) #设置查询框组件的位置
self.btnSearch.place(x=605,y=60) #设置按钮组件的位置
Button(self.root, text='显示全部数据', height='1', width='13', font=('宋体','11','bold'),
command=lambda: self.fntreeviewshow(self.fnstusort(self.fnrank()))).place(x=665, y=60) #显示所有数据按钮
#显示
self.cname=['id','name','chinese','math','english','total','rank'] #列的名称
self.ctag=['学号','姓名','语文','数学','英语','总分','排名'] #列的标题
self.tree=ttk.Treeview(self.root,columns=self.cname,show='headings') #创建一个树状列表
self.click_num = {'0': 2, '1': 1, '2': 1, '3': 1, '4': 1, '5': 1,'6':1} #排序点击次数,基数为升序,偶数为降序
self.treeid=self.tree.heading(self.cname[0], text=self.ctag[0],
command=lambda :self.fnstusort(self.fnrank(), 0)) #设置标题,点击按照学号排序
self.treename = self.tree.heading(self.cname[1], text=self.ctag[1],
command= lambda: self.fnstusort(self.fnrank(), 1)) #设置标题,点击按照姓名排序
self.treechinese = self.tree.heading(self.cname[2], text=self.ctag[2],
command=lambda: self.fnstusort(self.fnrank(), 3))#设置标题,点击按照语文排序
self.treemath = self.tree.heading(self.cname[3], text=self.ctag[3],
command=lambda: self.fnstusort(self.fnrank(), 3)) #设置标题,点击按照数学排序
self.treeenglish = self.tree.heading(self.cname[4], text=self.ctag[4],
command=lambda: self.fnstusort(self.fnrank(), 4))#设置标题,点击按照英语排序
self.treetotal = self.tree.heading(self.cname[5], text=self.ctag[5],
command=lambda: self.fnstusort(self.fnrank(), 5))#设置标题,点击按照总分排序
self.treerank = self.tree.heading(self.cname[6], text=self.ctag[6],
command=lambda: self.fnstusort(self.fnrank(), 6)) # 设置标题,点击按照总分排序
for i in range(len(self.cname)):
# self.tree.heading(self.cname[i],text=self.ctag[i],command=lambda :self.stusort(self.title_num[i])) #设置标题
self.tree.column(self.cname[i],width=70,anchor=CENTER) #设置列宽为70,居中对齐
self.tree.place(x=300,y=100) #设置树状列表的位置
self.VScroll1 = Scrollbar(self.tree, orient="vertical", command=self.tree.yview) # 为Treeview添加滚动条
self.VScroll1.place(relx=0.971, rely=0.10, relwidth=0.024, relheight=0.89) # 设置滚动条的相对位置和相对大小
self.tree.configure(yscrollcommand=self.VScroll1.set)
self.tree.bind('<<TreeviewSelect>>', func=self.fnmodify_delete_show) #点击结点,调用删除修改函数
#新增
self.lbf=LabelFrame(self.root,text='新增信息') #创建LabelFrame组件对象
self.lbf.place(x=20,y=93,width=230,height=220) #设置LabelFrame组件的位置
self.lbId=Label(self.lbf,text='学号:').place(x=5,y=5) #创建Label组件-学号,并设置其位置
self.lbName = Label(self.lbf, text='姓名:').place(x=5, y=35) # 创建Label组件-姓名,并设置其位置
self.lbChinese=Label(self.lbf,text='语文:').place(x=5,y=65) #创建Label组件-语文,并设置其位置
self.lbMath=Label(self.lbf,text='数学:').place(x=5,y=95) #创建Label组件-数学,并设置其位置
self.lbEnglish = Label(self.lbf, text='英语:').place(x=5, y=125) #创建Label组件-英语,并设置其位置
self.name = StringVar() #新增-姓名输入框变量
self.id = StringVar() #新增-学号输入框变量
self.chinese = StringVar() #新增-语文输入框变量
self.math = StringVar() #新增-数学输入框变量
self.english = StringVar() #新增-英语输入框变量
self.entryId=Entry(self.lbf,textvariable=self.id).place(x=55,y=5) #创建Entry组件-学号,并设置其位置
self.entryName = Entry(self.lbf, textvariable=self.name).place(x=55, y=35) # 创建Entry组件-姓名,并设置其位置
self.entryChinese=Entry(self.lbf,textvariable=self.chinese).place(x=55,y=65) #创建Entry组件-语文,并设置其位置
self.entryMath=Entry(self.lbf,textvariable=self.math).place(x=55,y=95) #创建Entry组件-数学,并设置其位置
self.entryEnglish=Entry(self.lbf,textvariable=self.english).place(x=55,y=125) #创建Entry组件-英语,并设置其位置
self.btninsert=Button(self.lbf,text='新增',width='6',height='1',font=('','11')
,command=self.fninsert).place(x=50,y=155)
self.btnreset=Button(self.lbf, text='重置', width='6', height='1', font=('', '11')
,command=self.fncancle).place(x=150, y=155)
#生成报表
self.lbf2 = LabelFrame(self.root, text='生成报表文件') #创建LabelFrame组件-生成报表文件对象
self.lbf2.place(x=20, y=330, width=230, height=100)
Button(self.lbf2, text='生成报表文件', height='2', width=15, font=('宋体','10','bold')
, command=self.fncreatcsv).place(x=55, y=15) #生成报表文件按钮
#修改删除
self.name2=StringVar() #修改删除-姓名输入框变量
self.id2 = StringVar() #修改删除-学号输入框变量
self.chinese2 = StringVar() #修改删除-语文输入框变量
self.math2 = StringVar() #修改删除-数学输入框变量
self.english2 = StringVar() #修改删除-英语输入框变量
self.total=StringVar() #修改删除-总分输入框变量
self.rank=StringVar() #修改删除-排名输入框变量
self.lbf3=LabelFrame(self.root,text='修改和删除') ##创建LabelFrame组件-生成报表修改删除
self.lbf3.place(x=300,y=330,width=493,height=100)
self.entryid=Entry(self.lbf3, width=6, textvariable=self.id2,state='disable').place(x=5, y=5) #设置Entry-学号为disable
self.entryname=Entry(self.lbf3,width=6,textvariable=self.name2,state='disable') #设置Entry-名字为disable
self.entryname.place(x=75,y=5)
self.entrychinese=Entry(self.lbf3,width=6,textvariable=self.chinese2,state='disable') #设置Entry-语文为disable
self.entrychinese.place(x=145,y=5)
self.entrymath=Entry(self.lbf3,width=6,textvariable=self.math2,state='disable') #设置Entry-数学为disable
self.entrymath.place(x=215,y=5)
self.entryenglish=Entry(self.lbf3,width=6,textvariable=self.english2,state='disable') #设置Entry-英语为disable
self.entryenglish.place(x=285,y=5)
self.entrytotal=Entry(self.lbf3,width=6,textvariable=self.total,state='disable') #设置Entry-总分为disable
self.entrytotal.place(x=355,y=5)
self.entryrank = Entry(self.lbf3, width=6, textvariable=self.rank, state='disable') # 设置Entry-排名为disable
self.entryrank.place(x=425, y=5)
Button(self.lbf3, text='修改', command=self.fnmodify).place(x=160, y=40) #修改按钮,单击调用事件self.modify
Button(self.lbf3, text='删除', command=self.fndeleteRecord).place(x=270, y=40) #删除按钮,单击调用事件self.deleteRecord
self.fnrank()
self.fntreeviewshow(self.fnstusort(self.fnrank())) # treeview显示数据
def mainInterface(self):
Label(self.root, text='学生成绩管理系统', font=('宋体', 15, 'bold')).pack()
self.logout=Label(self.root,text='注销',font=('宋体','10','underline'))
self.logout.place(x=550,y=25)
self.logout.configure(cursor="hand2")
self.logout.bind('<Button-1>',func=self.fnlogout)
welcome = self.account + ',欢迎您^V^'
Label(self.root, text=welcome, font=('宋体', '12', 'bold')).place(x=20, y=55)
# 生成报表文件
Button(self.root, text='生成报表文件', height='2', width=15,font=('宋体','12','bold')
,command=self.creatcsv).place(x=370, y=50) #生成报表文件按钮
#显示
cname=['id','name','Chinese','math','English','total','rank'] #列的名称
ctag=['学号','姓名','语文','数学','英语','总分','排名'] #列的标题
self.tree=ttk.Treeview(self.root,columns=cname,show='headings') #创建一个树状列表
for i in range(len(cname)):
self.tree.heading(cname[i],text=ctag[i]) #设置标题
self.tree.column(cname[i],width=70,anchor=CENTER) #设置列宽为70,居中对齐
self.tree.place(x=55,y=100)
student=self.rank(self.account)
self.treeviewshow(student)