前言:
此刻看官们对“学生成绩管理系统python源程序怎么写”可能比较珍视,我们都需要剖析一些“学生成绩管理系统python源程序怎么写”的相关文章。那么小编同时在网摘上网罗了一些对于“学生成绩管理系统python源程序怎么写””的相关资讯,希望小伙伴们能喜欢,看官们一起来学习一下吧!1.首先选定一个目录和文件夹,在其中新建如下几个文件。
图1
2.本文的路径和目录是,在编辑时自己可以根据个人的路径和目录适当调整,否则csv文件到时候打不开。
3.main.py代码
from tkinter import * from LoginPage import * #导入loginpage.py文件,里面有该窗口的相关设定root = Tk() root.title('Python成绩管理系统v1.0') root.geometry('1200x800+500+0')#其实这里只能设定+500+0的位置设定,大小需要回到loginpage.py中设定LoginPage(root) root.mainloop()
4.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('1200x800+500+0') 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, font=10,text = '账户: ').grid(row=1, stick=W, pady=10) Entry(self.page, font=10,textvariable=self.username).grid(row=1, column=1, stick=E) Label(self.page, font=10,text = '密码: ').grid(row=2, stick=W, pady=10) Entry(self.page, font=10,textvariable=self.password, show='*').grid(row=2, column=1, stick=E) #三个按钮 Button(self.page, font=10,text='登陆', command=self.loginCheck).grid(row=3, column=0, pady=5) Button(self.page,font=10, text='注册', command=self.register).grid(row=3, column=1, pady=5) Button(self.page, font=10,text='退出', command=self.page.quit).grid(row=3, column=2, pady=5) def loginCheck(self): name = self.username.get() password = self.password.get() if self.isLegalUser(name,password): self.page.destroy() MainPage(self.root) else: showinfo(title='错误', message='账号或密码错误!') def isLegal(self,string): alp = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] for i in string: if i in alp: pass else: return False return True def isLegalUser(self,name,password): #注意路径和目录,根据个人适当调整 f = open('/home/xgj/xgjpython/Python成绩管理系统(精简版)/账号密码.csv','r',encoding='utf-8') for line in f.readlines(): info = line[:-1].split(",") if len(info)<2: break if info[0].strip()==name and info[1].strip()==password : f.close() return True return False def register(self): name = self.username.get() password = self.password.get() if len(name)==0 or len(password)==0: showinfo(title='错误', message='账号密码不能为空') return for i in password: if i ==',' or i =='': showinfo(title='错误', message='密码不能含有非法字符') return if self.isLegal(name): pass else: showinfo(title='错误', message='账号不能含有非法字符') return f = open('/home/xgj/xgjpython/Python成绩管理系统(精简版)/账号密码.csv','r',encoding='utf-8') for line in f.readlines(): info = line[:-1].split(",") if len(info)<2: break if info[0].strip()==name: messagebox.showinfo(title='结果', message ="已存在该用户信息!") f.close() return f.close() f = open('/home/xgj/xgjpython/Python成绩管理系统(精简版)/账号密码.csv','a',encoding='utf-8') f.write('{},{}\n'.format(name,password)) f.close() messagebox.showinfo(title='提示', message ="注册成功")
5.MainPage.py代码
from tkinter import * from view import * #菜单栏对应的各个子页面 #定义类:MainPage(.py)作为模块,之后可以引用class MainPage(object): def __init__(self, master=None): self.root = master #定义内部变量root self.root.geometry('%dx%d' % (1000, 800)) #设置窗口大小 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='增', font=10,command = self.inputData) menubar.add_command(label='删', font=10,command = self.deleteData) menubar.add_command(label='改', font=10,command = self.modifyData) menubar.add_command(label='查',font=10, 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()
6.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,font=10) #录入信息的条框设置,包括字体大小和颜色 self.E2 = Entry(self,font=10) self.E3 = Entry(self,font=10) self.E4 = Entry(self,font=10) self.E5 = Entry(self,font=10) self.E6 = Entry(self,font=10) 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('/home/xgj/xgjpython/Python成绩管理系统(精简版)/成绩.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('/home/xgj/xgjpython/Python成绩管理系统(精简版)/成绩.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, font=10,text = '姓名: ').grid(row=1, stick=W, pady=10) self.E1.grid(row=1, column=1,stick=E) Label(self, font=10,text = '学号: ').grid(row=2, stick=W, pady=10) self.E2.grid(row=2, column=1, stick=E) Label(self, font=10,text = '科目: ').grid(row=3, stick=W, pady=10) self.E3.grid(row=3, column=1, stick=E) Label(self, font=10,text = '成绩: ').grid(row=4, stick=W, pady=10) self.E4.grid(row=4, column=1, stick=E) Button(self, font=10,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,font=10) self.E2 = Entry(self,font=10) 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("/home/xgj/xgjpython/Python成绩管理系统(精简版)/成绩.csv","r",encoding="utf-8") as f: lines = f.readlines() with open("/home/xgj/xgjpython/Python成绩管理系统(精简版)/成绩.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, font=10,text = '学号: ').grid(row=1, stick=W, pady=10) self.E1.grid(row=1, column=1, stick=E) Label(self, font=10, text = '科目: ').grid(row=2, stick=W, pady=10) self.E2.grid(row=2, column=1, stick=E) Button(self, font=10, 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,font=10) self.E2 = Entry(self,font=10) self.E3 = Entry(self,font=10) self.E4 = Entry(self,font=10) self.E5 = Entry(self,font=10) 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("/home/xgj/xgjpython/Python成绩管理系统(精简版)/成绩.csv","r",encoding="utf-8") as f: lines = f.readlines() with open("/home/xgj/xgjpython/Python成绩管理系统(精简版)/成绩.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, font=10,text = '姓名: ').grid(row=1, stick=W, pady=10) self.E1.grid(row=1, column=1, stick=E) Label(self, font=10, text = '学号: ').grid(row=2, stick=W, pady=10) self.E2.grid(row=2, column=1, stick=E) Label(self, font=10, text = '科目: ').grid(row=3, stick=W, pady=10) self.E3.grid(row=3, column=1, stick=E) Label(self, font=10,text = '成绩: ').grid(row=4, stick=W, pady=10) self.E4.grid(row=4, column=1, stick=E) Button(self, font=10, text='修改',command=self.click).grid(row=6, column=1, stick=E, pady=10) class QueryFrame(Frame): # 查--查询--query def __init__(self, master=None): Frame.__init__(self, master) self.root = master #定义内部变量root self.E1 = Entry(self,font=10) self.E2 = Entry(self,font=10) 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('/home/xgj/xgjpython/Python成绩管理系统(精简版)/成绩.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, font=10, text = '学号: ').grid(row=1, stick=W, pady=10) self.E1.grid(row=1, column=1, stick=E) Label(self, font=10,text = '科目: ').grid(row=2, stick=W, pady=10) self.E2.grid(row=2, column=1, stick=E) Button(self, font=10, text='查找',command=self.click).grid(row=6, column=1, stick=E, pady=10)
7.在文件夹内新建两个csv文件:成绩.csv和账号密码.csv
7.1 可以用excel新建
7.2 注意账号密码.csv的表头和name、password,如图2
7.3 成绩.csv可以只设表头名:成绩,里面内容可以是空的。
8.操作一下,看gif示例:
9.当然,你的先注册:admin和123,很简单,怎么样?喜欢吗?还可以多注册几个账号和密码,适用不同人使用。
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #学生成绩管理系统python源程序怎么写 #学生成绩管理系统python源程序怎么用 #python学生成绩管理系统tkinter界面