基于python+tkinter的学生成绩信息管理系统
基于python+tkinter的学生成绩信息管理系统
- 系统设计
2.开发工具
开发语言:python3.6.8
开发工具:JetBrains PyCharm 2019.1.2 x64
使用三方模块:os、tkinter、ttkbootstrap、messagebox、datetime、tkinter.ttk
3.系统展示
(1)登录界面
(2)管理界面
4.程序设计
Stu_login.py实现系统登录
Maingui.py 实现系统管理
studetailgui.py实现学生添加、修改、查看功能
changegui.py 实现用户权限,用户信息添加、密码修改
img存储程序需要的背景文件
data存储系统数据
5.Stu_login.py系统登录的实现
import os
from tkinter import *
from ttkbootstrap import *
from tkinter.messagebox import *
from datetime import *
import mainguiclass login_windows(Tk):def __init__(self):super().__init__() # 先执行tk这个类的初始化self.title("学生成绩信息管理系统登录界面V2.0")self.geometry("544x344+400+200")self.iconbitmap("./img/student.ico") # 给窗体增加一个图标self.resizable(0, 0) # 不允许改变窗体大小# 定义全局变量self.img_file = "./img/stu_login_png.png" # 文件路径self.user_file = "./data/user.txt"self.user_info_list = [] # 存储用户信息self.user = ""self.password = ""self.current_user_list = [] # 存储当前登录的用户名信息self.password_error_times = 0 # 记录密码错误次数# 运行函数self.setup_gui() # 加载界面显示函数self.load_user_info() # 加载用户信息存储文件def setup_gui(self):self.style01 = Style(theme="flatly") # 为窗体设置一个显示主题# 创建一个Label展示登录界面self.login_img = PhotoImage(file=self.img_file)self.label_img = Label(self, image=self.login_img)self.label_img.place(x=0, y=0)# 创建一个用户名label+entry标签self.label_user = Label(self, text="用户名:", font="微软雅黑 14 bold").place(x=20, y=304)self.var_user = StringVar()self.entry_user = Entry(self, width=10, textvariable=self.var_user, font="微软雅黑 14 bold").place(x=100, y=304)# 创建一个密码Label+entry标签self.label_password = Label(self, text="密码:", font="微软雅黑 14 bold").place(x=240, y=304)self.var_password = StringVar()self.entry_password = Entry(self, width=10, show="*", textvariable=self.var_password, font="微软雅黑 14 bold")self.entry_password.place(x=300, y=304)# 创建一个登录按钮self.login_button = Button(self, text="登录", width=8, font="微软雅黑 12 bold", command=self.login).place(x=450,y=302)def load_user_info(self):if not os.path.exists(self.user_file):showinfo("消息提示", "数据存储data文件中不存在用户存储信息文件!")else:try:with open(file=self.user_file, mode="r", encoding="utf-8") as refile:current = refile.readlines()for list in current:current_dic = dict(eval(list))self.user_info_list.append(current_dic)except:showinfo("消息提示", "文件读取异常")def login(self):# 获取输入的用户名和密码self.user = self.var_user.get()self.password = self.var_password.get()# 身份验证for index in self.user_info_list:# 判断输入的用户名是否正确if self.user.strip().lower() == index["user"]:# 判断账号是否被禁用if index["times"] != "0":showinfo("消息提示", "账号已被禁用,无法登录,请联系管理员!")break# 判断密码是否正确if self.password != index["password"]:self.password_error_times += 1 # 记录登录次数# print(self.password_error_times)if self.password_error_times >= 3:showinfo("消息提示", "密码错误已达三次!账号已锁定!")# 改变状态index["times"] = "2"# 将状态改变后的信息写入文件self.write_user_info(self.user_info_list)else:showinfo("消息提示", "输入密码错误!")else:self.times = 0self.current_user_list.append(index)self.login_main_windows()break# showinfo("消息提示", "系统登录成功!")else:showinfo("消息提示", "该用户不存在!")breakdef write_user_info(self, user: list):try:with open(file=self.user_file, mode="w", encoding="utf-8") as wfile:for index in user:wfile.write(str(index) + "\n")except:showinfo("消息提示", "写入文件异常")def login_main_windows(self):self.destroy() # 关闭当前窗口# 打开新窗口maingui.Main_Windows(self.current_user_list, self.get_login_time())def get_login_time(self):# 获取当前时间today = datetime.today()return ("%04d-%02d-%02d %02d:%02d:%02d" % (today.year, today.month, today.day, today.hour, today.minute, today.second))if __name__ == "__main__":this_windows = login_windows()this_windows.mainloop()
6.maingui.py系统管理界面的实现
import os
from tkinter import *
from tkinter.ttk import Treeviewfrom ttkbootstrap import *
from tkinter.messagebox import *
import studetailgui
import changeguiclass Main_Windows(Tk):def __init__(self, current_user_list, current_login_time):super().__init__()self.title("欢迎使用学生成绩信息管理系统V2.0")self.geometry("1280x720+120+20")self.iconbitmap("./img/student.ico") # 位窗体添加一个图标self["bg"] = "RoyalBlue"# 文件路径self.student_file = "./data/student.txt"# 定义全局变量self.current_login_time = current_login_timeself.current_login_user_list = current_user_listself.all_student_info = [] # 存储学生信息self.query_result_student = [] # 存储查询信息self.sort_result_student = [] # 存储排序后的学生信息self.action_flag = 0 # 标记变量self.current_student_info = [] # 存储当前的学生信息self.change_flag = 0 # 用户信息标记变量# 运行函数self.setup_gui() # 加载显示界面self.load_student_file() # 加载学生信息self.load_student_info_treeview(self.all_student_info)def setup_gui(self):# 添加一个显示主题self.style01 = Style(theme="flatly")# 添加一个显示标签self.label_title = Label(self, text="学生成绩信息管理系统", font="微软雅黑 40 bold", relief="groove")self.label_title.place(relwidth=1, relheight=0.18, relx=0, rely=0)# 添加登录用户和时间显示标签self.label_login_time = Label(self, text=self.current_login_time, font="微软雅黑 12")self.label_login_time.place(relwidth=0.15, relheight=0.05, relx=0.84, rely=0.12)self.label_login_user = Label(self, text="当前登录用户:" + self.get_login_user(), font="微软雅黑 12")self.label_login_user.place(relwidth=0.15, relheight=0.05, relx=0.84, rely=0.08)# 添加左侧显示区域self.Pane_left = PanedWindow(self, relief="groove")self.Pane_left.place(relwidth=0.15, relheight=0.82, relx=0, rely=0.18)# 添加信息录入按钮self.add_button = Button(self.Pane_left, text="录入学生信息", font="微软雅黑 12 bold", command=self.add_student_info)self.add_button.place(relwidth=1, relheight=0.08, relx=0, rely=0.05)# 添加删除信息按钮self.del_button = Button(self.Pane_left, text="删除学生信息", font="微软雅黑 12 bold", command=self.del_student_info)self.del_button.place(relwidth=1, relheight=0.08, relx=0, rely=0.18)# 添加删除信息按钮self.mod_button = Button(self.Pane_left, text="修改学生信息", font="微软雅黑 12 bold", command=self.upadte_student_info)self.mod_button.place(relwidth=1, relheight=0.08, relx=0, rely=0.31)# 添加密码修改按钮self.user_mod_button = Button(self.Pane_left, text="用户权限更改", font="微软雅黑 12 bold",command=self.permission_upadte)self.user_mod_button.place(relwidth=1, relheight=0.08, relx=0, rely=0.44)# 成绩单打印self.user_mod_button = Button(self.Pane_left, text="用户密码修改", font="微软雅黑 12 bold", command=self.update_user_info)self.user_mod_button.place(relwidth=1, relheight=0.08, relx=0, rely=0.57)# 添加用户添加按钮self.user_add_button = Button(self.Pane_left, text="用户添加", font="微软雅黑 12 bold", command=self.add_user_info)self.user_add_button.place(relwidth=1, relheight=0.08, relx=0, rely=0.70)# 添加退出系统按钮self.exit_button = Button(self.Pane_left, text="退出系统", font="微软雅黑 12 bold", command=self.exit_windows)self.exit_button.place(relwidth=1, relheight=0.08, relx=0, rely=0.83)# 添加右侧显示区域self.Pane_right = PanedWindow(self, relief="groove")self.Pane_right.place(relwidth=0.849, relheight=0.82, relx=0.15, rely=0.18)# 添加查询选择区域self.labelFrame = LabelFrame(self.Pane_right, text="请输入要查询的学生信息", foreground="red")self.labelFrame.place(relwidth=0.99, relheight=0.1, relx=0.01, rely=0)# 添加学号self.id_label = Label(self.labelFrame, text="学号:", font="微软雅黑 12")self.id_label.place(relwidth=0.1, relheight=0.8, relx=0, rely=0.1)# 添加学号输入区域self.var_id = StringVar()self.id_entry = Entry(self.labelFrame, textvariable=self.var_id, font="微软雅黑 12")self.id_entry.place(relwidth=0.15, relheight=0.8, relx=0.08, rely=0.1)# 添加姓名self.name_label = Label(self.labelFrame, text="姓名:", font="微软雅黑 12")self.name_label.place(relwidth=0.1, relheight=0.8, relx=0.25, rely=0.1)# 添加姓名输入区域self.var_name = StringVar()self.name_entry = Entry(self.labelFrame, textvariable=self.var_name, font="微软雅黑 12")self.name_entry.place(relwidth=0.15, relheight=0.8, relx=0.33, rely=0.1)# 添加班级self.classes_label = Label(self.labelFrame, text="班级:", font="微软雅黑 12")self.classes_label.place(relwidth=0.1, relheight=0.8, relx=0.5, rely=0.1)# 添加姓名输入区域self.var_classes = StringVar()self.classes_entry = Entry(self.labelFrame, textvariable=self.var_classes, font="微软雅黑 12")self.classes_entry.place(relwidth=0.15, relheight=0.8, relx=0.58, rely=0.1)# 添加查询按钮self.query_button = Button(self.labelFrame, text="查询", font="微软雅黑 12", command=self.query_student)self.query_button.place(relwidth=0.08, relheight=0.8, relx=0.8, rely=0.1)# 添加显示全部按钮self.show_button = Button(self.labelFrame, text="显示全部", font="微软雅黑 12", command=self.show_all_student)self.show_button.place(relwidth=0.08, relheight=0.8, relx=0.91, rely=0.1)# 添加学生信息排序区域self.labelSort = LabelFrame(self.Pane_right, text="请选择成绩信息排序条件", foreground="red")self.labelSort.place(relwidth=0.99, relheight=0.1, relx=0.01, rely=0.1)# 添加排序条件self.var_sort = IntVar()self.total = Radiobutton(self.labelSort, text="总分", variable=self.var_sort, value=1, font="微软雅黑 12")self.total.place(relwidth=0.06, relheight=0.8, relx=0.02, rely=0.1)# 语文self.chinese = Radiobutton(self.labelSort, text="语文", variable=self.var_sort, value=2, font="微软雅黑 12")self.chinese.place(relwidth=0.06, relheight=0.8, relx=0.1, rely=0.1)# 数学self.maths = Radiobutton(self.labelSort, text="数学", variable=self.var_sort, value=3, font="微软雅黑 12")self.maths.place(relwidth=0.06, relheight=0.8, relx=0.18, rely=0.1)# 英语self.english = Radiobutton(self.labelSort, text="英语", variable=self.var_sort, value=4, font="微软雅黑 12")self.english.place(relwidth=0.06, relheight=0.8, relx=0.26, rely=0.1)# 物理self.physics = Radiobutton(self.labelSort, text="物理", variable=self.var_sort, value=5, font="微软雅黑 12")self.physics.place(relwidth=0.06, relheight=0.8, relx=0.34, rely=0.1)# 化学self.chemistry = Radiobutton(self.labelSort, text="化学", variable=self.var_sort, value=6, font="微软雅黑 12")self.chemistry.place(relwidth=0.06, relheight=0.8, relx=0.42, rely=0.1)# 生物self.biology = Radiobutton(self.labelSort, text="生物", variable=self.var_sort, value=7, font="微软雅黑 12")self.biology.place(relwidth=0.06, relheight=0.8, relx=0.50, rely=0.1)# 历史self.history = Radiobutton(self.labelSort, text="历史", variable=self.var_sort, value=8, font="微软雅黑 12")self.history.place(relwidth=0.06, relheight=0.8, relx=0.58, rely=0.1)# 地理self.geography = Radiobutton(self.labelSort, text="地理", variable=self.var_sort, value=9, font="微软雅黑 12")self.geography.place(relwidth=0.06, relheight=0.8, relx=0.66, rely=0.1)# 政治self.plitics = Radiobutton(self.labelSort, text="政治", variable=self.var_sort, value=10, font="微软雅黑 12")self.plitics.place(relwidth=0.06, relheight=0.8, relx=0.74, rely=0.1)# 添加排序按钮self.sort_button = Button(self.labelSort, text="排序", font="微软雅黑 12", command=self.sort_tree_student)self.sort_button.place(relwidth=0.08, relheight=0.8, relx=0.91, rely=0.1)# 添加treeview显示控件self.Tree = Treeview(self.Pane_right,columns=("id", "name", "classes", "chinese", "maths", "english", "physics", "chemistry","biology","history", "geography", "plitics", "total"),show="headings", height=24)# 设置每一个列的宽度和对齐方式self.Tree.column("id", width=100, anchor="center")self.Tree.column("name", width=80, anchor="center")self.Tree.column("classes", width=70, anchor="center")self.Tree.column("chinese", width=70, anchor="center")self.Tree.column("maths", width=70, anchor="center")self.Tree.column("english", width=70, anchor="center")self.Tree.column("physics", width=70, anchor="center")self.Tree.column("chemistry", width=70, anchor="center")self.Tree.column("biology", width=70, anchor="center")self.Tree.column("history", width=70, anchor="center")self.Tree.column("geography", width=70, anchor="center")self.Tree.column("plitics", width=70, anchor="center")self.Tree.column("total", width=70, anchor="center")# 设置每个列的标题self.Tree.heading("id", text="学号")self.Tree.heading("name", text="姓名")self.Tree.heading("classes", text="班级")self.Tree.heading("chinese", text="语文")self.Tree.heading("maths", text="数学")self.Tree.heading("english", text="英语")self.Tree.heading("physics", text="物理")self.Tree.heading("chemistry", text="化学")self.Tree.heading("biology", text="生物")self.Tree.heading("history", text="历史")self.Tree.heading("geography", text="地理")self.Tree.heading("plitics", text="政治")self.Tree.heading("total", text="总分")# 设置Tree摆放位置self.Tree.place(relwidth=0.99, relheight=0.8, relx=0.01, rely=0.20)# 添加触发双击某一行的事件self.Tree.bind("<Double-1>", self.view_student_info)def get_login_user(self):for index in self.current_login_user_list:return str(index["user"])def load_student_file(self):if not os.path.exists(self.student_file):showinfo("消息提示", "暂未在存储文件夹DATA中找到学生信息存储文件!")else:try:with open(file=self.student_file, mode="r", encoding="utf-8") as rfile:current_line = rfile.readlines() # 读取学生信息for list in current_line:current_dic = dict(eval(list)) # 将字符串转换成字典self.all_student_info.append(current_dic) # 将数据存储学生存储列表中# print(self.all_student_info)except:showinfo("消息提示", "学生信息存储文件读取异常")def load_student_info_treeview(self, student_info: list):# 清空treevie显示信息for i in self.Tree.get_children():self.Tree.delete(i)# 判断是否存在数据if not student_info:showinfo("消息提示", "暂时没有要显示的数据!")else:try:for index in student_info:# 将数据插入到tree中显示self.Tree.insert("", END, values=(index["id"], index["name"], index["classes"], index["chinese"], index["maths"],index["english"], index["physics"], index["chemistry"], index["biology"], index["history"],index["geography"], index["plitics"], index["total"]))except:showinfo("消息提示", "数据显示错误")def query_student(self):"""查询学生信息:return:"""# 清空查询列表self.query_result_student.clear()# 准备条件获取查询查询参数query_dic = dict() # 定义一个空字典用来存储查询参数query_dic["id"] = self.var_id.get().strip() # 获取学号query_dic["name"] = self.var_name.get().strip() # 获取姓名query_dic["classes"] = self.var_classes.get().strip() # 获取班级信息# 遍历所有符合条件的学生for index in self.all_student_info:if query_dic["id"] in index["id"] and query_dic["name"] in index["name"] and query_dic["classes"] in index["classes"]:# 将满足条件的学生插入查询列表self.query_result_student.append(index)# 将查询结果显示在treeview中self.load_student_info_treeview(self.query_result_student)def show_all_student(self):"""显示全部学生信息:return:"""# 清空查询参数self.var_id.set("")self.var_name.set("")self.var_classes.set("")# 将所有学生信息显示至treeview中self.load_student_info_treeview(self.all_student_info)def sort_tree_student(self):"""对总学生或查询学生成绩信息进行排序:return:"""# 清空排序结果存储列表self.sort_result_student.clear()# 遍历所有的学生信息for index in self.all_student_info:self.sort_result_student.append(index)# 对所有的学生成绩按总分进行降序排序# print(self.var_sort.get())if self.var_sort.get() == 1:# 按总分降序排列self.sort_result_student.sort(key=lambda x: x["total"], reverse=True)elif self.var_sort.get() == 2:# 按语文成绩降序排列self.sort_result_student.sort(key=lambda x: x["chinese"], reverse=True)elif self.var_sort.get() == 3:# 按数学成绩降序排列self.sort_result_student.sort(key=lambda x: x["maths"], reverse=True)elif self.var_sort.get() == 4:# 按英语成绩降序排列self.sort_result_student.sort(key=lambda x: x["english"], reverse=True)elif self.var_sort.get() == 5:# 按物理成绩降序排列self.sort_result_student.sort(key=lambda x: x["physics"], reverse=True)elif self.var_sort.get() == 6:# 按化学成绩降序排列self.sort_result_student.sort(key=lambda x: x["chemistry"], reverse=True)elif self.var_sort.get() == 7:# 按生物成绩降序排列self.sort_result_student.sort(key=lambda x: x["biology"], reverse=True)elif self.var_sort.get() == 8:# 按历史成绩降序排列self.sort_result_student.sort(key=lambda x: x["history"], reverse=True)elif self.var_sort.get() == 9:# 按地理成绩降序排列self.sort_result_student.sort(key=lambda x: x["geography"], reverse=True)elif self.var_sort.get() == 10:# 按政治成绩降序排列self.sort_result_student.sort(key=lambda x: x["plitics"], reverse=True)else:# 显示左右学生的成绩信息,不做排列self.load_student_info_treeview(self.all_student_info)# 将排序结果显示在treeview中self.load_student_info_treeview(self.sort_result_student)def view_student_info(self, event):"""查看学生成绩信息:return:"""self.action_flag = 1# 获取双击行的数据item = self.Tree.selection()[0]temp_student_list = self.Tree.item(item, "values")for index in self.all_student_info:if index["id"] == temp_student_list[0]:self.current_student_info = index# 加载明细窗体self.load_detail_student_gui()def del_student_info(self):"""删除学生信息:return:"""try:# 获取双击行的数据item = self.Tree.selection()temp_student_list = self.Tree.item(item, "values")# 询问是否删除choose = askyesno("删除确认", "确认要删除学生信息【学号:" + temp_student_list[0] + " 姓名:" + temp_student_list[1]+ "】信息吗?")if choose:for index in range(len(self.all_student_info)):if temp_student_list[0] == self.all_student_info[index]["id"]:self.all_student_info.pop(index)break# 更新数据表格显示self.load_student_info_treeview(self.all_student_info)# 将删除后的数据写入文件self.write_to_file()# 成功提示showinfo("消息提示", "消息删除成功!")else:returnexcept:showinfo("消息提示", "请先选择要删除的学生信息!")def load_detail_student_gui(self):"""加载学生信息明细窗口:return:"""detail_windows = studetailgui.detail_windows(self.action_flag, self.current_student_info, self.all_student_info)self.wait_window(detail_windows)return detail_windows.userinfodef add_student_info(self):"""录入学生信息:return:"""self.action_flag = 2if self.load_detail_student_gui() == 1:# 将所有的信息显示在treeview中self.load_student_info_treeview(self.all_student_info)# 将学生信息写入文件self.write_to_file()else:returndef upadte_student_info(self):"""修改学生信息:return:"""self.action_flag = 3# 获取双击行的数据try:item = self.Tree.selection()[0]temp_student_list = self.Tree.item(item, "values")for index in self.all_student_info:if index["id"] == temp_student_list[0]:self.current_student_info = index# 加载窗体if self.load_detail_student_gui() == 1:self.load_student_info_treeview(self.all_student_info)self.write_to_file()else:returnexcept:showinfo("消息提示", "请先选择要修改的学生!")def write_to_file(self):"""将学生信息写入文件:param all_student_info::return:"""if os.path.exists(self.student_file):try:with open(file=self.student_file, mode="w", encoding="utf-8") as wfile:for index in self.all_student_info:wfile.write(str(index) + "\n")except:showinfo("消息提示", "文件写入错误!")def exit_windows(self):# 关闭住显示窗口self.destroy()def load_change_gui(self):"""加载用户信息修改窗口:return:"""change_windows = changegui.change_windows(self.change_flag, self.current_login_user_list)self.wait_window(change_windows)return change_windows.user_infodef add_user_info(self):"""添加用户信息:return:"""self.change_flag = 2self.load_change_gui()def update_user_info(self):"""修改用户信息:return:"""self.change_flag = 1if self.load_change_gui() == 1:showinfo("消息提示", "用户密码已经修改,请重新登录!")self.destroy()def permission_upadte(self):if self.current_login_user_list[0]["user"] == "admin":self.change_flag = 3self.load_change_gui()else:showinfo("消息提示", "你还不是管理员,无权对用户权限进行更改!")returnif __name__ == "__main__":windows = Main_Windows()windows.mainloop()
7.studetail.py明细信息窗口功能的实现
from tkinter import *
from ttkbootstrap import *
from tkinter.messagebox import *class detail_windows(Toplevel):def __init__(self, action_flag: int, current_student_info: dict, all_student_info: list):super().__init__()self.title("学生信息明细界面")self.geometry("400x400+400+300")self.resizable(0, 0) # 不允许改变窗体大小self.iconbitmap("./img/student.ico")# 定义全局变量self.action_flag = action_flagself.current_student_info = current_student_infoself.all_student_info = all_student_info# 加载显示界面self.setup_gui()self.load_maingui_flag()# 把窗体的行为捕获转为方法self.protocol("WM_DELETE_WINDOW", self.close_window)def setup_gui(self):# 给界面添加一个主题self.style01 = Style(theme="flatly")# 添加一个titleself.var_title = StringVar()self.title_label = Label(self, textvariable=self.var_title, font="微软雅黑 16 bold", foreground="darkred",relief="groove")self.title_label.place(relwidth=0.99, relheight=0.15, relx=0.005, rely=0)# 添加一个区域显示窗体self.Pane = PanedWindow(self, relief="groove")self.Pane.place(relwidth=0.99, relheight=0.85, relx=0.005, rely=0.15)# 添加学号标签self.id_label = Label(self.Pane, text="学号:", font="微软雅黑 10 bold")self.id_label.place(relwidth=0.2, relheight=0.1, relx=0, rely=0.01)self.var_id = StringVar()self.id_Entry = Entry(self.Pane, textvariable=self.var_id, font="微软雅黑 10 bold")self.id_Entry.place(relwidth=0.3, relheight=0.1, relx=0.15, rely=0.01)# 添加一个姓名标签self.name_label = Label(self.Pane, text="姓名:", font="微软雅黑 10 bold")self.name_label.place(relwidth=0.2, relheight=0.1, relx=0.5, rely=0.01)self.var_name = StringVar()self.name_Entry = Entry(self.Pane, textvariable=self.var_name, font="微软雅黑 10 bold")self.name_Entry.place(relwidth=0.3, relheight=0.1, relx=0.65, rely=0.01)# 添加班级标签self.classes_label = Label(self.Pane, text="班级:", font="微软雅黑 10 bold")self.classes_label.place(relwidth=0.2, relheight=0.1, relx=0, rely=0.15)self.var_classes = StringVar()self.classes_Entry = Entry(self.Pane, textvariable=self.var_classes, font="微软雅黑 10 bold")self.classes_Entry.place(relwidth=0.3, relheight=0.1, relx=0.15, rely=0.15)# 添加一个语文标签self.chinese_label = Label(self.Pane, text="语文:", font="微软雅黑 10 bold")self.chinese_label.place(relwidth=0.2, relheight=0.1, relx=0.5, rely=0.15)self.var_chinese = StringVar()self.chinese_Entry = Entry(self.Pane, textvariable=self.var_chinese, font="微软雅黑 10 bold")self.chinese_Entry.place(relwidth=0.3, relheight=0.1, relx=0.65, rely=0.15)# 添加数学标签self.maths_label = Label(self.Pane, text="数学:", font="微软雅黑 10 bold")self.maths_label.place(relwidth=0.2, relheight=0.1, relx=0, rely=0.29)self.var_maths = StringVar()self.maths_Entry = Entry(self.Pane, textvariable=self.var_maths, font="微软雅黑 10 bold")self.maths_Entry.place(relwidth=0.3, relheight=0.1, relx=0.15, rely=0.29)# 添加一个英语标签self.english_label = Label(self.Pane, text="英语:", font="微软雅黑 10 bold")self.english_label.place(relwidth=0.2, relheight=0.1, relx=0.5, rely=0.29)self.var_english = StringVar()self.english_Entry = Entry(self.Pane, textvariable=self.var_english, font="微软雅黑 10 bold")self.english_Entry.place(relwidth=0.3, relheight=0.1, relx=0.65, rely=0.29)# 添加物理标签self.physics_label = Label(self.Pane, text="物理:", font="微软雅黑 10 bold")self.physics_label.place(relwidth=0.2, relheight=0.1, relx=0, rely=0.43)self.var_physics = StringVar()self.physics_Entry = Entry(self.Pane, textvariable=self.var_physics, font="微软雅黑 10 bold")self.physics_Entry.place(relwidth=0.3, relheight=0.1, relx=0.15, rely=0.43)# 添加一个化学标签self.chemistry_label = Label(self.Pane, text="化学:", font="微软雅黑 10 bold")self.chemistry_label.place(relwidth=0.2, relheight=0.1, relx=0.5, rely=0.43)self.var_chemistry = StringVar()self.chemistry_Entry = Entry(self.Pane, textvariable=self.var_chemistry, font="微软雅黑 10 bold")self.chemistry_Entry.place(relwidth=0.3, relheight=0.1, relx=0.65, rely=0.43)# 添加生物标签self.biology_label = Label(self.Pane, text="生物:", font="微软雅黑 10 bold")self.biology_label.place(relwidth=0.2, relheight=0.1, relx=0, rely=0.57)self.var_biology = StringVar()self.biology_Entry = Entry(self.Pane, textvariable=self.var_biology, font="微软雅黑 10 bold")self.biology_Entry.place(relwidth=0.3, relheight=0.1, relx=0.15, rely=0.57)# 添加一个历史标签self.history_label = Label(self.Pane, text="历史:", font="微软雅黑 10 bold")self.history_label.place(relwidth=0.2, relheight=0.1, relx=0.5, rely=0.57)self.var_history = StringVar()self.history_Entry = Entry(self.Pane, textvariable=self.var_history, font="微软雅黑 10 bold")self.history_Entry.place(relwidth=0.3, relheight=0.1, relx=0.65, rely=0.57)# 添加地理标签self.geography_label = Label(self.Pane, text="地理:", font="微软雅黑 10 bold")self.geography_label.place(relwidth=0.2, relheight=0.1, relx=0, rely=0.71)self.var_geography = StringVar()self.geography_Entry = Entry(self.Pane, textvariable=self.var_geography, font="微软雅黑 10 bold")self.geography_Entry.place(relwidth=0.3, relheight=0.1, relx=0.15, rely=0.71)# 添加一个政治标签self.plitics_label = Label(self.Pane, text="政治:", font="微软雅黑 10 bold")self.plitics_label.place(relwidth=0.2, relheight=0.1, relx=0.5, rely=0.71)self.var_plitics = StringVar()self.plitics_Entry = Entry(self.Pane, textvariable=self.var_plitics, font="微软雅黑 10 bold")self.plitics_Entry.place(relwidth=0.3, relheight=0.1, relx=0.65, rely=0.71)# 添加保存按钮self.save_button = Button(self, text="保存", font="微软雅黑 10 bold", command=self.save_commit)self.save_button.place(relwidth=0.2, relheight=0.1, relx=0.4, rely=0.87)# 添加关闭按钮self.close_button = Button(self, text="关闭", font="微软雅黑 10 bold", command=self.close_window)self.close_button.place(relwidth=0.2, relheight=0.1, relx=0.74, rely=0.87)def load_maingui_flag(self):if self.action_flag == 1:self.var_title.set("==查看学生明细信息==")# 加载数据self.load_student_detail()# 设置控件状态为不可改变self.save_button.forget()self.id_Entry["state"] = DISABLEDself.name_Entry["state"] = DISABLEDself.classes_Entry["state"] = DISABLEDself.chinese_Entry["state"] = DISABLEDself.maths_Entry["state"] = DISABLEDself.english_Entry["state"] = DISABLEDself.physics_Entry["state"] = DISABLEDself.chemistry_Entry["state"] = DISABLEDself.biology_Entry["state"] = DISABLEDself.history_Entry["state"] = DISABLEDself.geography_Entry["state"] = DISABLEDself.plitics_Entry["state"] = DISABLEDelif self.action_flag == 2:self.var_title.set("==添加学生明细信息==")elif self.action_flag == 3:self.var_title.set("==修改学生明细信息==")# 填充数据self.load_student_detail()# 学号不允许修改self.id_Entry["state"] = DISABLEDdef load_student_detail(self):if not self.current_student_info:showinfo("消息提示", "没有任何信息可以展示!")else:self.var_id.set(str(self.current_student_info["id"]))self.var_name.set(str(self.current_student_info["name"]))self.var_classes.set(str(self.current_student_info["classes"]))self.var_chinese.set(str(self.current_student_info["chinese"]))self.var_maths.set(str(self.current_student_info["maths"]))self.var_english.set(str(self.current_student_info["english"]))self.var_physics.set(str(self.current_student_info["physics"]))self.var_chemistry.set(str(self.current_student_info["chemistry"]))self.var_biology.set(str(self.current_student_info["biology"]))self.var_history.set(str(self.current_student_info["history"]))self.var_geography.set(str(self.current_student_info["geography"]))self.var_plitics.set(str(self.current_student_info["plitics"]))def save_commit(self):if self.action_flag == 1:passelif self.action_flag == 2:# 准备数据temp_dic = dict()if len(str(self.var_id.get().strip())) == 0:showinfo("消息提示", "学号不能为空!")else:try:temp_dic["id"] = str(self.var_id.get().strip()) # 获取学号temp_dic["name"] = str(self.var_name.get().strip()) # 获取姓名temp_dic["classes"] = str(self.var_classes.get().strip()) # 获取班级temp_dic["chinese"] = float(self.var_chinese.get().strip()) # 获取语文temp_dic["maths"] = float(self.var_maths.get().strip()) # 获取数学temp_dic["english"] = float(self.var_english.get().strip()) # 获取英语成绩temp_dic["physics"] = float(self.var_physics.get().strip()) # 获取物理成绩temp_dic["chemistry"] = float(self.var_chemistry.get().strip()) # 获取化学temp_dic["biology"] = float(self.var_biology.get().strip()) # 获取生物temp_dic["history"] = float(self.var_history.get().strip()) # 获取历史成绩temp_dic["geography"] = float(self.var_geography.get().strip()) # 获取地理成绩temp_dic["plitics"] = float(self.var_plitics.get().strip()) # 获取政治成绩temp_dic["total"] = temp_dic["chinese"] + temp_dic["maths"] + temp_dic["english"] + temp_dic["physics"] + temp_dic["chemistry"] + temp_dic["biology"] + temp_dic["history"] + temp_dic["geography"] + temp_dic["plitics"]for index in range(len(self.all_student_info)):if temp_dic["id"] == self.all_student_info[index]["id"]:showinfo("消息提示", "输入学生信息已经存在,请重新输入!")# 将所有消息恢复为空self.var_id.set("")self.var_name.set("")self.var_classes.set("")self.var_chinese.set("")self.var_maths.set("")self.var_english.set("")self.var_physics.set("")self.var_chemistry.set("")self.var_biology.set("")self.var_history.set("")self.var_geography.set("")self.var_plitics.set("")breakelse:self.all_student_info.append(temp_dic)showinfo("消息提示", "学生信息添加成功!")# 反馈信号给主窗体self.userinfo = 1# 关闭窗口self.destroy()breakexcept:showinfo("消息提示", "输入数据类型错误")elif self.action_flag == 3:# 准备数据temp_dic = dict()if len(str(self.var_id.get().strip())) == 0:showinfo("消息提示", "学号不能为空!")else:try:temp_dic["id"] = str(self.var_id.get().strip()) # 获取学号temp_dic["name"] = str(self.var_name.get().strip()) # 获取姓名temp_dic["classes"] = str(self.var_classes.get().strip()) # 获取班级temp_dic["chinese"] = float(self.var_chinese.get().strip()) # 获取语文temp_dic["maths"] = float(self.var_maths.get().strip()) # 获取数学temp_dic["english"] = float(self.var_english.get().strip()) # 获取英语成绩temp_dic["physics"] = float(self.var_physics.get().strip()) # 获取物理成绩temp_dic["chemistry"] = float(self.var_chemistry.get().strip()) # 获取化学temp_dic["biology"] = float(self.var_biology.get().strip()) # 获取生物temp_dic["history"] = float(self.var_history.get().strip()) # 获取历史成绩temp_dic["geography"] = float(self.var_geography.get().strip()) # 获取地理成绩temp_dic["plitics"] = float(self.var_plitics.get().strip()) # 获取政治成绩temp_dic["total"] = temp_dic["chinese"] + temp_dic["maths"] + temp_dic["english"] + temp_dic["physics"] + temp_dic["chemistry"] + temp_dic["biology"] + temp_dic["history"] + temp_dic["geography"] + temp_dic["plitics"]# print(temp_dic)# 遍历存储列表for index in range(len(self.all_student_info)):if temp_dic["id"] == self.all_student_info[index]["id"]:# 删除原来的数据self.all_student_info[index] = temp_dic# 将新数据修改后的数据添加到列表# self.all_student_info.append(temp_dic)showinfo("消息提示", "学生信息修改成功!")# 反馈信号给主窗体self.userinfo = 1# 关闭窗体self.destroy()except:showinfo("消息提示", "输入数据类型错误!")def close_window(self):self.userinfo = 0self.destroy()
8.changegui.py用户信息边界功能的实现
import os
from tkinter import *
from ttkbootstrap import *
from tkinter.messagebox import *class change_windows(Toplevel):def __init__(self, change_flag: int, current_login_list: dict):super().__init__()self.title("用户信息窗口")self.geometry("300x300+400+300")self.resizable(0, 0)self.iconbitmap("./img/student.ico")# 定义全局变量self.change_flag = change_flagself.current_login_list = current_login_list # 存储当前登录用户信息self.user_file = "./data/user.txt" # 用户文件self.all_user_list = [] # 存储所有用户的信息# 加载函数self.setup_gui()self.load_maingui_flag()self.read_user_file()# 把窗体的行为捕获转为方法self.protocol("WM_DELETE_WINDOW", self.close_windows)def setup_gui(self):self.style01 = Style(theme="flatly")# 添加一个titleself.var_title = StringVar()self.title_label = Label(self, textvariable=self.var_title, font="微软雅黑 16 bold", foreground="darkred",relief="groove")self.title_label.place(relwidth=0.99, relheight=0.15, relx=0.005, rely=0)# 添加一个区域显示窗体self.Pane = PanedWindow(self, relief="groove")self.Pane.place(relwidth=0.99, relheight=0.85, relx=0.005, rely=0.15)# 添加用户名标签self.user_label = Label(self.Pane, text="用户名:", font="微软雅黑 10 bold")self.user_label.place(relwidth=0.2, relheight=0.15, relx=0.03, rely=0.1)self.var_user = StringVar()self.user_Entry = Entry(self.Pane, textvariable=self.var_user, font="微软雅黑 10 bold")self.user_Entry.place(relwidth=0.7, relheight=0.15, relx=0.20, rely=0.1)# 添加密码标签self.password_label = Label(self.Pane, text="密码:", font="微软雅黑 10 bold")self.password_label.place(relwidth=0.2, relheight=0.15, relx=0.05, rely=0.4)self.var_password = StringVar()self.password_Entry = Entry(self.Pane, textvariable=self.var_password, font="微软雅黑 10 bold")self.password_Entry.place(relwidth=0.7, relheight=0.15, relx=0.20, rely=0.4)# 添加保存按钮self.save_button = Button(self, text="保存", font="微软雅黑 10 bold", command=self.save_commit)self.save_button.place(relwidth=0.2, relheight=0.1, relx=0.4, rely=0.87)def load_maingui_flag(self):if self.change_flag == 1:self.var_title.set("==用户密码修改==")self.user_Entry["state"] = DISABLEDself.var_user.set(self.current_login_list[0]["user"])elif self.change_flag == 2:self.var_title.set("==添加用户信息==")elif self.change_flag == 3:self.var_title.set("==用户权限更改==")def save_commit(self):"""保存用户信息修改:return:"""if self.change_flag == 1:temp_dic = dict()try:temp_dic["user"] = str(self.var_user.get().strip())temp_dic["password"] = str(self.var_password.get().strip())temp_dic["times"] = "0"for index in range(len(self.all_user_list)):if temp_dic["user"] == self.all_user_list[index]["user"]:self.all_user_list[index] = temp_dicshowinfo("消息提示", "密码修改成功!")# 将修改后的密码保存至文件中self.write_user_to_file()# 反馈信号给主窗体self.user_info = 1self.destroy()except:showinfo("消息提示", "输入数据类型错误")elif self.change_flag == 2:temp_dic = dict()if len(str(self.var_user.get().strip())) == 0:showinfo("消息提示", "用户名不能为空!")else:try:temp_dic["user"] = str(self.var_user.get().strip()) # 获取用户名temp_dic["password"] = str(self.var_password.get().strip()) # 获取密码temp_dic["times"] = "0"for index in range(len(self.all_user_list)):if temp_dic["user"] == self.all_user_list[index]["user"]:showinfo("消息提示", "用户名已经存在,请重新输入!")self.var_user.set("")self.var_password.set("")breakelse:self.all_user_list.append(temp_dic)showinfo("消息提示", "用户信息添加成功!")self.user_info = 0self.destroy()breakself.write_user_to_file()except:showinfo("消息提示", "输入数据类型错误!")elif self.change_flag == 3:temp_dic = dict()if len(str(self.var_user.get().strip())) == 0:showinfo("消息提示", "用户名不能为空!")else:try:temp_dic["user"] = str(self.var_user.get().strip()) # 获取用户名temp_dic["password"] = str(self.var_password.get().strip()) # 获取密码temp_dic["times"] = "0"for index in range(len(self.all_user_list)):if temp_dic["user"] == self.all_user_list[index]["user"]:self.all_user_list[index] = temp_dicshowinfo("消息提示", "用户权限修改成功!")# 关闭窗口self.destroy()# 反馈信号给主窗体self.user_info = 1self.write_user_to_file()except:showinfo("消息提示", "输入数据类型错误!")def close_windows(self):self.destroy()self.user_info = 0def read_user_file(self):if os.path.exists(self.user_file):try:with open(self.user_file, mode="r", encoding="utf-8") as rfile:temp_user = rfile.readlines()for list in temp_user:temp_dic = dict(eval(list))self.all_user_list.append(temp_dic)except:showinfo("消息提示", "用户信息文件读取错误!")else:showinfo("消息提示", "data中暂不存在保存的用户信息文件!")def write_user_to_file(self):if os.path.exists(self.user_file):try:with open(self.user_file, mode="w", encoding="utf-8") as wfile:for index in self.all_user_list:wfile.write(str(index) + "\n")except:showinfo("消息提示", "用户信息写入错误!")else:showinfo("消息提示", "用户信息写入错误!")
需要程序源码的请至https://download.csdn.net/download/qq_25327943/87862925进行下载。
基于python+tkinter的学生成绩信息管理系统相关推荐
- 基于JavaWeb学生成绩信息管理系统(附源码资料)-毕业设计
1. 适用人群 本课程主要是针对计算机专业相关正在做毕业设计.或者是需要实战项目的Java开发学习者. 2. 你将收获 提供:项目源码.项目文档.数据库脚本.软件工具等所有资料(在平台的课程附件中进行 ...
- 【基于SSM+MySQL+Jsp的高校学生成绩信息管理系统的设计与实现 ---(效果+源代码+数据库+获取 ~ ~】
快速阅读目录 写在前面: (一)效果展示 (1)数据库表一览 (2)部分运行截图 (二)代码展示 (三)说明 写在前面: tips:这是一个基于SSM+MySQL+Jsp等技术的高校学生成绩信息管理系 ...
- C语言编写学生成绩信息管理系统
用C语言设计简单的学生成绩信息管理系统 介绍 代码 结构体数组的定义 home_page() 函数 add_infor() 函数 browse_infor() 函数 find_infor() 函数 m ...
- 任务2 学生成绩信息管理系统
系列文章 任务2 学生成绩信息管理系统 某班级学生C语言第一次正考的成绩存于数据文件score.txt中,记录了学生学号.姓名和考试成绩,bk.txt文件中记录了补考学生的学号.姓名和补考成绩,编写程 ...
- C#程序代码连接SQL Server数据库实现学生成绩信息管理系统(重置版)
目录 一.创建数据库表和配置SQL数据库连接信息 1.创建数据库表 2.配置数据库连接信息 二.配置程序代码 1.StudentAccount类 2.Student类 3.TeacherAccount ...
- 基于jsp+mysql+mybatis+Spring boot简单学生成绩信息管理系统
1.项目开发背景和意义 随着科学技术的快速发展和不断提高,尤其是计算机科学技术的日渐普及,其功能的强大以及运行速度已经被人们深刻地了解.近几年来高校的办学模式多元化和学校规模的扩大,为了实现对学生信息 ...
- C语言学生成绩信息管理系统课程设计报告
C语言课程设计报告 一 .设计目的 学生成绩管理系统 主要功能: (1)能按学期.按班级完成对学生成绩的录入. 修改,删除 (2)能按班级统计学生的成绩,求学生的总分及 平均分,并能根据学生的平均成绩 ...
- 基于Java Web的学生就业信息管理系统
一.项目介绍 学生就业信息管理系统是针对大学毕业生就业情况进行统计和管理的系统,通过此系统可以方便对毕业生的就业情况进行管理.模块上分:就业信息.就业统计.用户管理.登录/登出三个主要模块. 二.技术 ...
- 【课程设计】基于java GUI实现学生个人信息管理系统(源码+论文+ppt+视频)
源码资料 免费下载 不经常在线,需要源码和资料的留言私信我,主页有联系方式 技术架构 开发语言 主要用的是Java语言中的GUI(图形用户界面)和AWT(抽象窗口工具包)编程. (1) GUI 图形用 ...
最新文章
- kset_create_and_add
- metapath2vec: Scalable Representation Learning for Heterogeneous Networks
- 新建了一个英文Blog
- 2016php技术面试题,一个php的面试题,大家看看
- Pytorch 神经网络nn模块
- 视频增强之“动态范围扩展”HDR技术漫谈
- 2.4 在不同的划分上进行训练并测试
- 重装系统的悲剧。。。。。
- .NET基础 (08)字符串处理
- 「腾讯地图」小程序插件
- WebService 入门教程(Java)
- electron 屏幕标注_gInk:一款好用的屏幕标注写画软件
- 极光im支持android手机系统,极光IM- JMessage 产品简介 - 极光文档
- 第一章 计算机网络概述(计算机网络韩立刚)
- 健康小贴士:喝酒时别点哪些菜_新闻中心_新浪网
- 云巡店php源码,雅量云巡店赋能陈列管理 提效降本看得见
- cardboard下载_如何在Android上设置Google Cardboard
- 国产手机操作系统 COS 官方回应 7 大质疑
- 使用osmconvert转换pbf文件至osm文件
- 幼儿课外活动游戏_适合幼儿园的课外活动有哪些游戏
热门文章
- 双目相机标定理论总结
- 面对“烟囱式”难题,联想企业网盘展现跨时空延展能力
- 动态建表格(来自https://www.cnblogs.com/mr-wuxiansheng/p/6363570.html)
- 对于一遍遍历的众数求法
- 虚拟内存,内存页面错误与页面错误增量如何处理。(整理)
- Kubernetes基础:在MacOS上安装Kubernetes
- c++:算术运算符、赋值运算符、比较运算符、逻辑运算符
- hdu 5687 Problem C trie树
- Linux flock文件锁详解
- sql查询出1到12月的数据形成报表