侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

python实现简单成绩录入系统

Python  /  管理员 发布于 7年前   196

学了一个多月的python,做了一个小程序:python实现简单成绩录入系统,实验一下

menu部分

from tkinter import*#这是一个python模块,python3中都有import tkinter.messagebox#这也是一个模块from file_read import readfrom file_write import write class student_main():#定义一个学生类 def __init__(self):  self.name =''  self.ID=''  self.lessons={}  self.sum=''  self.average=''stulist=read()stu=student_main()#登录页面--------------------------------------------------------------------def seacharID(stulist,ID):#这是一个对是否重复id的检验 for x in stulist: if x.ID==ID:  return True#这是一个成绩录入时的主要函数def next(): root_next=Tk() root_next.title('成绩录入') root_next.geometry('200x200+230+330') var_lesson=StringVar() var_score=StringVar() Label(root_next,text='课程名').place(x=20,y=50) Label(root_next,text='成绩').place(x=20,y=90) enter_lesson=Entry(root_next,textvariable=var_lesson,width=15) enter_lesson.place(x=70,y=50) enter_score=Entry(root_next,textvariable=var_score,width=15) enter_score.place(x=70,y=90) def btn3_login(): x=var_lesson.get() y=var_score.get() if y.isdigit()==True:  if int(y)>100:  tkinter.messagebox.showerror('错误','请输入正确的成绩!!!')  var_score.set('')  elif int(y)<0:  tkinter.messagebox.showerror('错误','请输入正确的成绩!!!')  var_score.set('')  else:  stu.lessons[x]=y  root_next.destroy()  next() else:  tkinter.messagebox.showwarning('提示','请输入数字') def btn4_login(): x=var_lesson.get() y=var_score.get() stu.lessons[x]=y tkinter.messagebox.showinfo('录入成功') root_next.destroy()   btn3=Button(root_next,text='录入新学科',bg='#5EAEFF',bd=0,command=btn3_login) btn3.place(y=130,width=99,height=20) btn4=Button(root_next,text='完成',bg='#FF6868',bd=0,command=btn4_login) btn4.place(x=101,y=130,width=99,height=20)  #页面循环 root_next.mainloop()#核心函数def entry(): root_e=Tk() root_e.title("增") root_e.geometry('200x200+230+330') var_user=StringVar() var_ID=StringVar() Label(root_e,text='姓名').place(x=20,y=50) Label(root_e,text='ID').place(x=20,y=90) enter_user=Entry(root_e,textvariable=var_user,width=15) enter_user.place(x=70,y=50) enter_user.focus() enter_ID=Entry(root_e,textvariable=var_ID,width=15) enter_ID.place(x=70,y=90) def btn1_login(): x=var_user.get() y=var_ID.get() pop=seacharID(stulist,y) if pop==True:  tkinter.messagebox.showwarning('错误','该学号已存在')  var_ID.set("")  var_user.set("") else:  if y.isdigit()==True:  conunt=0  sum_opp=0  stu.name=x  stu.ID=y  root_e.destroy()  next()    for x in stu.lessons.values():   sum_opp=sum_opp+int(x)   conunt+=1  stu.sum=str(sum_opp)  average_opp=int(stu.sum)/conunt  stu.average=str(average_opp)  stulist.append(stu)    write(stulist)  menu()  else:  tkinter.messagebox.showwarning('提示','您输入了非数字的内容')  var_ID.set(" ") def btn2_login(): root_e.destroy() menu() btn1=Button(root_e,text='下一步',command=btn1_login,bd=0,bg='Silver') btn1.place(y=140,width=99,height=20) btn2=Button(root_e,text='取消',command=btn2_login,bd=0,bg='Silver') btn2.place(x=100,y=140,width=99,height=20) root_e.mainloop()#删除页面------------------------------------------------------------------def deling(): root=Tk() root.title('删') root.geometry('200x200+230+330') Label(root,text='学号').place(x=40,y=50) def btn_ok(): x=var_del.get() if x.isdigit()==True:  count=0  for i in stulist:  if i.ID==x:   stulist.remove(i)   write(stulist)   tkinter.messagebox.showinfo("提示",'成功删除该学生信息')   root.destroy()   menu()  else:   count+=1  if count==len(stulist):  tkinter.messagebox.showinfo(title='错误',message='不存在该账户!')  var_del.set('') else:  tkinter.messagebox.showerror('警告','请输入数字') def btn_cancel(): x=tkinter.messagebox.askokcancel('提示','确定离开?') if x==True:  root.destroy() menu() var_del=StringVar() entry_del=Entry(root,textvariable=var_del,width=10) entry_del.place(x=80,y=50) btn1=Button(root,bd=0,bg='Silver',command=btn_ok,text='确定') btn1.place(y=110,width=99,height=20) btn2=Button(root,bd=0,bg='Silver',command=btn_cancel,text='取消') btn2.place(x=101,y=110,width=99,height=20) root.mainloop()#修改页面---------------------------------------------------------------def change(): root=Tk() root.title("改") root.geometry('200x200+230+330') Label(root,text='学号').place(x=40,y=50) var_change=StringVar() entry_change=Entry(root,textvariable=var_change,width=10) entry_change.place(x=80,y=50) def var_ok(): x=var_change.get() if x.isdigit()==True:  counton=0  for i in stulist:  if x==i.ID:   stulist.remove(i)   write(stulist)   root.destroy()   entry()  else:   counton+=1  if counton==len(stulist):  tkinter.messagebox.showerror('错误','不存在该账户!') else:  tkinter.messagebox.showerror('警告','输入数字ID') def var_cancel(): x=tkinter.messagebox.askokcancel('提示','确定离开') if x==True:  root.destroy() btn1=Button(root,bd=0,bg='Silver',command=var_ok,text='确定') btn1.place(y=110,width=99,height=20) btn2=Button(root,bd=0,bg='Silver',command=var_cancel,text='取消') btn2.place(x=101,y=110,width=99,height=20) root.mainloop()#查询页面------------------------------------------------------------------def next_i(x): window=Tk() window.title('显示信息') window.geometry('400x200') counton=0 for i in stulist: if i.ID==x:  ai_name=i.name  ai_ID=i.ID  ai_lesson=str(i.lessons)  ai_sum=i.sum  ai_ave=i.average else:  ai_name=' '  ai_ID=' '  ai_lesson='该学号不存在'  ai_sum=' '  ai_ave=' '   Label(window,height=2,width=8,text=ai_name).pack() Label(window,height=2,width=8,text=ai_ID).pack() Label(window,height=2,width=100,text=ai_lesson).pack() Label(window,height=2,width=8,text=ai_sum).pack() Label(window,height=2,width=8,text=ai_ave).pack() window.mainloop()def search(): root=Tk() root.title('') root.geometry('200x200+230+330') Label(root,text='学号').place(x=40,y=50) def btn_ok(): x=var_display.get() if x.isdigit()==True:  next_i(x) else:  tkinter.messagebox.showerror('警告','请输入数字ID') def btn_cancel(): root.destroy() menu() var_display=StringVar() entry_display=Entry(root,textvariable=var_display,width=10) entry_display.place(x=80,y=50) btn1=Button(root,bd=0,bg='Silver',command=btn_ok,text='确定') btn1.place(y=110,width=99,height=20) btn2=Button(root,bd=0,bg='Silver',command=btn_cancel,text='返回主菜单') btn2.place(x=101,y=110,width=99,height=20) root.mainloop()#排序页面--------------------------------------------------------------def display(x): window=Tk() window.title() contunt=0 for i in x: contunt+=1 all_list=['第'+str(contunt)+'名:'] all_list.append('姓名:'+i.name+'\\') all_list.append('学号:'+i.ID+'\\') for m,n in i.lessons.items():  all_list.append(m+":")  all_list.append(n)  all_list.append('\\') all_list.append('总分:'+i.sum+'\\') all_list.append('平均分:'+i.average) Label(window,bd=20,text=all_list).pack() window.mainloop()def sorting(): for i in range(len(stulist)-1): for j in range(i+1,len(stulist)):  temp=student_main()  if stulist[i].average<stulist[j].average:  temp=stulist[i]  stulist[i]=stulist[j]  stulist[j]=temp display(stulist)#菜单------------------------------------------------------def menu(): root=Tk() root.title('主视面') root.geometry('250x300+150+100') def var_one(): root.destroy() entry() def var_two(): root.destroy() deling() def var_three(): root.destroy() change() def var_four(): root.destroy() search() def var_five(): sorting() def var_six(): root.destroy()  var0=Label(root,text='--------------菜单--------------',font=('Arial',13),width=30,height=1) var0.pack() var1=Button(root,text='1.添加界面',bg='Silver',font=('Arial',12),width=20,height=1,bd=0,command=var_one) var1.pack(pady=4) var2=Button(root,text='2.删除界面',bg='Silver',font=('Arial',12),width=20,height=1,bd=0,command=var_two) var2.pack(pady=4) var3=Button(root,text='3.更改界面',bg='Silver',font=('Arial',12),width=20,height=1,bd=0,command=var_three) var3.pack(pady=4) var4=Button(root,text='4.查询界面',bg='Silver',font=('Arial',12),width=20,height=1,bd=0,command=var_four) var4.pack(pady=4) var4=Button(root,text='5.成绩排序',bg='Silver',font=('Arial',12),width=20,height=1,bd=0,command=var_five) var4.pack(pady=4) var6=Button(root,text='退出',bg='Silver',font=('Arial',12),width=20,height=1,bd=0,command=var_six) var6.pack(pady=4) root.mainloop()menu()

file_read模块部分

(file_read主要是将我储存在txt文件中的数据转化成stulist列表,来进行检验,防止录入同一个id)

class student_main(): def __init__(self):  self.name =''  self.ID=''  self.lessons={}  self.sum=''  self.average=''def read(): stulist=[] x=[] f=open('all_student.txt','r') t=open('all_lesson.txt','r') line=f.readlines() lene=t.readlines() for i in range(len(line)): if (i+1)%2==1:#这里主要是读取和储存是出现了莫名的空行,我只好多录入一个空行好方便读取  y=student_main()  x=line[i].split(" ")  y.name=x[0]  y.ID=x[1]  j=int((i+1)/2)  z=eval(lene[j])  y.lessons=z  y.sum=x[2]  y.average=x[3]  stulist.append(y) return stulist 

file_write模块部分

(主要是将menu中获得的数据进行储存)

class student_main(): def __init__(self):  self.name =''  self.ID=''  self.lessons={}  self.sum=''  self.average=''def write(stulist): f=open('all_student.txt','w') for i in stulist: f.write(i.name+' '+i.ID+' '+i.sum+' '+i.average) f.write('\n') f.close() t=open('all_lesson.txt','w') for i in stulist: t.write(str(i.lessons)) t.write('\n') t.close()

还要自己建立两个TXT文本,一个叫all_lesson.txt,另一个叫all_student.txt。

因为student类中的lesson是用字典储存的,我实在找不到怎么把他完整的读出来的语句只好分开存储了。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


  • 上一条:
    python BlockingScheduler定时任务及其他方式的实现
    下一条:
    淘宝秒杀python脚本 扫码登录版
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在python语言中Flask框架的学习及简单功能示例(0个评论)
    • 在Python语言中实现GUI全屏倒计时代码示例(0个评论)
    • Python + zipfile库实现zip文件解压自动化脚本示例(0个评论)
    • python爬虫BeautifulSoup快速抓取网站图片(1个评论)
    • vscode 配置 python3开发环境的方法(0个评论)
    • 近期文章
    • 智能合约Solidity学习CryptoZombie第四课:僵尸作战系统(0个评论)
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2018-04
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2022-01
    • 2023-07
    • 2023-10
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客