python学生信息管理系统tkinter_python tkinter 学生信息管理系统

该博客介绍了一个使用Tkinter库创建的Python学生信息管理系统。系统包括添加、删除、修改和查询学生信息的功能,通过Tkinter的Frame和Tkinter的Font模块实现页面布局和字体设置,具有友好的用户界面。
摘要由CSDN通过智能技术生成

1 from tkinter import * 2 importtkinter.font as tkFont3 importtkinter as tk4 from tkinter importttk5 6 LARGE_FONT= ("Verdana", 20)7 8 #窗口每页内容更换 9 classApplication(tk.Tk):10 def __init__(self):11 12 super().__init__()13 14 self.wm_title("学生信息管理系统")15 16 container =tk.Frame(self)17 container.pack(side="top", fill="both", expand =True)18 container.grid_rowconfigure(0, weight=1)19 container.grid_columnconfigure(0, weight=1)20 21 self.frames ={}22 for F in(StartPage, PageOne, PageTwo, PageThree,PageFour):23 frame =F(container, self)24 self.frames[F] =frame25 frame.grid(row=0, column=0, sticky="nsew") #四个页面的位置都是 grid(row=0, column=0), 位置重叠,只有最上面的可见!! 26 27 self.show_frame(StartPage)28 29 30 defshow_frame(self, cont):31 frame =self.frames[cont]32 frame.tkraise() #切换,提升当前 tk.Frame z轴顺序(使可见)!!此语句是本程序的点睛之处 33 34 35 classStartPage(tk.Frame):36 ‘‘‘主页‘‘‘ 37 def __init__(self, parent, root):38 super().__init__(parent)39 label = tk.Label(self, text="学生信息管理系统", font=LARGE_FONT)40 label.pack(pady=100)41 ft2=tkFont.Font(size=16)42 Button(self, text="添加学生信息",font=ft2,command=lambda: root.show_frame(PageOne),width=30,height=2,fg=‘white‘,bg=‘gray‘,activebackground=‘black‘,activeforeground=‘white‘).pack()43 Button(self, text="删除学生信息",font=ft2,command=lambda: root.show_frame(PageTwo),width=30,height=2).pack()44 Button(self, text="修改学生信息",font=ft2,command=lambda: root.show_frame(PageThree),width=30,height=2,fg=‘white‘,bg=‘gray‘,activebackground=‘black‘,activeforeground=‘white‘).pack()45 Button(self, text="查询学生信息",font=ft2,command=lambda: root.show_frame(PageFour),width=30,height=2).pack()46 Button(self,text=‘退出系统‘,height=2,font=ft2,width=30,command=root.destroy,fg=‘white‘,bg=‘gray‘,activebackground=‘black‘,activeforeground=‘white‘).pack()47 48 49 50 #添加学生信息 51 classPageOne(tk.Frame):52 def __init__(self, parent, root):53 super().__init__(parent)54 label = tk.Label(self, text="添加学生信息", font=LARGE_FONT)55 label.pack(pady=100)56 57 ft3=tkFont.Font(size=14)58 ft4=tkFont.Font(size=12)59 Label(self,text=‘学生学号:‘,font=ft3).pack(side=TOP)60 globale161 e1=StringVar()62 Entry(self,width=30,textvariable=e1,font=ft3,bg=‘Ivory‘).pack(side=TOP)63 Label(self,text=‘学生姓名:‘,font=ft3).pack(side=TOP)64 globale265 e2=StringVar()66 Entry(self,width=30,textvariable=e2,font=ft3,bg=‘Ivory‘).pack(side=TOP)67 Label(self,text=‘学生成绩:‘,font=ft3).pack(side=TOP)68 globale369 e3=StringVar()70 Entry(self,width=30,textvariable=e3,font=ft3,bg=‘Ivory‘).pack(side=TOP)71 Button(self, text="返回首页",width=8,font=ft4,command=lambda: root.show_frame(StartPage)).pack(pady=20)72 Button(self, text="确定保存",width=8,font=ft4,command=self.save).pack(side=TOP)73 74 defsave(self):75 with open(‘student_infor.txt‘,‘a+‘) as student_infor:76 num=str(e1.get())77 name=str(e2.get())78 score=str(e3.get())79 student_infor.write(num+‘ ‘+name+‘ ‘+score+‘\n‘)80 81 #删除学生信息 82 classPageTwo(tk.Frame):83 def __init__(self, parent, root):84 super().__init__(parent)85 label = tk.Label(self, text="添加学生信息", font=LARGE_FONT)86 label.pack(pady=100)87 88 ft3=tkFont.Font(size=14)89 ft4=tkFont.Font(size=12)90 Label(self,text=‘请输入你要删除的学生学号:‘,font=ft3).pack(side=TOP)91 globale492 e4=StringVar()93 Entry(self,width=30,textvariable=e4,font=ft3,bg=‘Ivory‘).pack(side=TOP)94 Button(self, text="确定删除",width=8,font=ft4,command=self.del1).pack(pady=20)95 Button(self, text="返回首页",width=8,font=ft4,command=lambda: root.show_frame(StartPage)).pack()96 defdel1(self):97 num2=str(e4.get())98 with open(‘student_infor.txt‘,‘r‘) as f:99 lines=f.readlines()100 with open(‘student_infor.txt‘,‘w‘) as f_w:101 for line inlines:102 if num2 inline:103 continue 104 f_w.write(line)105 106 #修改学生信息 107 classPageThree(tk.Frame):108 def __init__(self, parent, root):109 super().__init__(parent)110 tk.Label(self, text="修改学生信息", font=LARGE_FONT).pack(pady=100)111 112 ft3=tkFont.Font(size=14)113 ft4=tkFont.Font(size=12)114 Label(self,text=‘请输入你要修改的学生学号:‘,font=ft3).pack(side=TOP)115 self.e5=StringVar()116 Entry(self,width=30,textvariable=self.e5,font=ft3,bg=‘Ivory‘).pack(side=TOP)117 Label(self,text=‘学生姓名:‘,font=ft3).pack(side=TOP)118 self.e6=StringVar()119 Entry(self,width=30,textvariable=self.e6,font=ft3,bg=‘Ivory‘).pack(side=TOP)120 Label(self,text=‘学生成绩:‘,font=ft3).pack(side=TOP)121 self.e7=StringVar()122 Entry(self,width=30,textvariable=self.e7,font=ft3,bg=‘Ivory‘).pack(side=TOP)123 Button(self, text="确定修改",width=8,font=ft4,command=self.modify).pack(pady=20)124 Button(self, text="返回首页",width=8,font=ft4,command=lambda: root.show_frame(StartPage)).pack()125 defmodify(self):126 num3=str(self.e5.get())127 name3=str(self.e6.get())128 score3=str(self.e7.get())129 with open(‘student_infor.txt‘,‘r‘) as r_w:130 lines1=r_w.readlines()131 with open(‘student_infor.txt‘,‘w‘) as rr_w:132 for line1 inlines1:133 if num3 inline1:134 rr_w.write(num3+‘ ‘+name3+‘ ‘+score3+‘\n‘)135 continue 136 rr_w.write(line1)137 138 #查询学生成绩 139 classPageFour(tk.Frame):140 def __init__(self, parent, root):141 super().__init__(parent)142 label = tk.Label(self, text="查询学生成绩", font=LARGE_FONT)143 label.pack(pady=100)144 tree_data=ttk.Treeview()145 ft4=tkFont.Font(size=12)146 #滚动条 147 148 scro=Scrollbar(self)149 150 scro.pack(side=RIGHT,fill=Y)151 lista=Listbox(self,yscrollcommand=scro.set,width=50)152 153 f=open(‘student_infor.txt‘,‘r‘)154 text=("%-16s%-16s%-16s"%("学号","姓名","成绩"))155 156 li=[]157 for i inf.readlines():158 j=i.split(‘ ‘)159 j[2]=j[2].replace(‘\n‘,‘‘)160 li.append(j)161 li.sort(key=lambda x:x[2],reverse=False)162 for i inli:163 text1=("%-16s%-16s%-16s"%(i[0],i[1],i[2]))164 lista.insert(0,text1)165 f.close()166 lista.insert(0,text)167 lista.pack()168 Button(self, text="返回首页",width=8,font=ft4,command=lambda: root.show_frame(StartPage)).pack(pady=40)169 170 171 if __name__ == ‘__main__‘:172 #实例化Application 173 app =Application()174 175 #主消息循环: 176 app.mainloop()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值