From f2bc7cc0a113d69dbf2647b0d269051d03a93530 Mon Sep 17 00:00:00 2001 From: select <1377671356@qq.com> Date: Sun, 2 Jun 2024 16:14:48 +0800 Subject: [PATCH] first select --- SystemDesign.py | 347 +++++++++++++++++++++++++++++ select.py | 575 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 922 insertions(+) create mode 100644 SystemDesign.py create mode 100644 select.py diff --git a/SystemDesign.py b/SystemDesign.py new file mode 100644 index 0000000..f9d16b3 --- /dev/null +++ b/SystemDesign.py @@ -0,0 +1,347 @@ +import os +import time + + +class Problem: # 定义试题信息的类 + def __init__(self, num, question, choice_a, choice_b, choice_c, choice_d, answer): + self.num = num + self.question = question + self.choice_a = choice_a + self.choice_b = choice_b + self.choice_c = choice_c + self.choice_d = choice_d + self.answer = answer + + +class Student: # 定义学生信息的类 + def __init__(self, name, user_name, user_password, grade, usetime): + self.name = name + self.user_name = user_name + self.user_password = user_password + self.grade = grade + self.usetime = usetime + + +# 基本功能都由这个类的方法实现 +class Manage: + def __init__(self): + self.StudentInfo = [] + self.ProblemInfo = [] + + @staticmethod + def main_menu(): + print("***************") + print("1.管理员端登录") + print("2.学生端登录") + print("3.注册学生端账户") + print("4.退出系统") + print("***************") + + @staticmethod + def administrator_menu(): + print("***************") + print("1.录入试题信息") + print("2.查看学生信息") + print("3.排名学生成绩") + print("4.查看试题信息") + print("5.分析总体答题情况") + print("6.删除学生信息") + print("7.删除试题信息") + print("8.返回上级") + print("***************") + + @staticmethod + def student_menu(): + print("***************") + print("1.开始答题") + print("2.返回上级") + print("***************") + + @staticmethod + def log_in(): + psw = int(input("请输入管理员密码")) + if psw == 123456: + Manage.administrator_menu() + while 1: + operate_administrator = int(input("请输入要选择的操作")) + if operate_administrator == 1: + Manage.add_problem(start) + Manage.administrator_menu() + if operate_administrator == 2: + Manage.show_student(start) + if operate_administrator == 3: + Manage.rank_student(start) + if operate_administrator == 4: + Manage.show_problem(start) + if operate_administrator == 5: + Manage.analysis_student(start) + if operate_administrator == 6: + Manage.del_student(start) + if operate_administrator == 7: + Manage.del_problem(start) + if operate_administrator == 8: + Manage.main_menu() + return + else: + print("账号或密码错误,已返回上级!") + Manage.main_menu() + + def register(self): + print("***************") + new_student = Student(name=input("输入你的用户名"), + user_name=input("输入你的账号"), + user_password=input("输入你的密码"), + grade="暂无成绩", + usetime="暂无信息") + temp = {"用户名": new_student.name, "账号": new_student.user_name, "密码": new_student.user_password, + "成绩": new_student.grade, "答题时间": new_student.usetime} + # 这里的new_student不能直接传入列表,要放在一个字典里把数据”打包“过去 + self.StudentInfo.append(temp) + print("注册成功!") + self.save_information() + self.main_menu() + + def student_login(self): + print("***************") + temp1 = input("请输入你的账号") + temp2 = input("请输入你的密码") + if len(self.StudentInfo) == 0: + # 如果学生信息为空,说明还没有账号注册,当作账号或密码错误处理 + print("账号或密码错误!已返回上级") + self.main_menu() + return + for stu in self.StudentInfo: # 循环遍历列表判断账号和密码是否正确 + if stu["账号"] == temp1 and stu["密码"] == temp2: + print("登录成功!欢迎你%s同学" % (stu["用户名"])) + self.student_menu() + while 1: + operate_student = int(input("请输入要选择的操作")) + if operate_student == 1: + self.test_begin(stu["用户名"]) + self.main_menu() + return + if operate_student == 2: + self.main_menu() + return + else: + print("账号或密码错误!已返回上级") + self.main_menu() + + def add_problem(self): + new_problem = Problem(num=input("输入题号"), + question=input("输入题目"), + choice_a=input("输入选项A"), + choice_b=input("输入选项B"), + choice_c=input("输入选项C"), + choice_d=input("输入选项D"), + answer=input("输入正确答案")) + temp = {"题号": new_problem.num, "题目": new_problem.question, "选项A": new_problem.choice_a, + "选项B": new_problem.choice_b, "选项C": new_problem.choice_c, "选项D": new_problem.choice_d, + "正确答案": new_problem.answer} + self.ProblemInfo.append(temp) + # 和学生信息一样,试题信息也要打包在一个字典里面后添加到列表 + print("录入成功!") + self.save_information() + + def del_student(self): + user_name = input("输入要删除的学生账号") + index = 0 + for stu in self.StudentInfo: + if stu["账号"] == user_name: + del self.StudentInfo[index] + self.save_information() + print("删除成功") + self.administrator_menu() + return + index += 1 + print("未查询到学生信息!") + self.administrator_menu() + return + + def del_problem(self): + num = input("输入要删除的题目题号") + index = 0 + for pro in self.ProblemInfo: + if pro["题号"] == num: + del self.ProblemInfo[index] + self.save_information() + print("删除成功") + self.administrator_menu() + return + index += 1 + print("未查询到试题信息!") + self.administrator_menu() + return + + def show_student(self): + if len(self.StudentInfo) == 0: + print("暂无学生信息") + self.administrator_menu() + return + for stu in self.StudentInfo: + print(stu) + input("按任意键继续") + self.administrator_menu() + return + + def show_problem(self): + if len(self.ProblemInfo) == 0: + print("暂无试题信息") + for pro in self.ProblemInfo: + print("%s:%s\n" + "A.%s\n" + "B.%s\n" + "C.%s\n" + "D.%s\n" + "正确答案:%s" + % (pro["题号"], pro["题目"], pro["选项A"], pro["选项B"], pro["选项C"], pro["选项D"], + pro["正确答案"])) + input("按任意键继续") + self.administrator_menu() + return + + def test_begin(self, name): + # 答题功能的主要功能由循坏遍历列表和time模板实现 + if len(self.ProblemInfo) == 0: + print("暂无试题信息") + self.student_menu() + return + grade = 0 + print("Test Begin!") + start_time = time.time() + for pro in self.ProblemInfo: + print("%s:%s\n" + "A.%s\n" + "B.%s\n" + "C.%s\n" + "D.%s\n" + % (pro["题号"], pro["题目"], pro["选项A"], pro["选项B"], pro["选项C"], pro["选项D"])) + answer = input("输入你的答案") + if answer == pro["正确答案"]: + grade += 5 + end_time = time.time() + for stu in self.StudentInfo: + if stu["用户名"] == name: + stu["成绩"] = str(grade) + stu["答题时间"] = str(int((end_time - start_time))) + break + print("Test Over!\n你的成绩是%d分,用时%d秒" % (grade, end_time - start_time)) + self.save_information() + return + + def rank_student(self): + if len(start.StudentInfo) == 0: + print("暂无学生信息") + return + tool = self.StudentInfo + for del_zero in tool: + if del_zero["成绩"] == "暂无成绩": + del_zero["成绩"] = -1 + temp = sorted(tool, key=lambda x: int(x["成绩"]), reverse=True) + rank = 1 + for stu in temp: + if stu["成绩"] == -1: + stu["成绩"] = "暂无成绩" + print("第%d名:%s %s分 用时%s秒" % (rank, stu["用户名"], stu["成绩"], stu["答题时间"])) + rank += 1 + input("按任意键继续") + self.administrator_menu() + return + + def analysis_student(self): + # 分析参加考试的人数,平均分 + if len(self.StudentInfo) == 0: + print("暂无答题信息") + self.administrator_menu() + return + print("本次测试有%d道题目" % (len(self.ProblemInfo))) + print("满分%d分" % (len(self.ProblemInfo) * 5)) + student_num = 0 + total = 0 + for stu in self.StudentInfo: + if stu["成绩"] == "暂无成绩": + continue + total += int(stu["成绩"]) + student_num += 1 + if student_num == 0: + print("暂无答题信息") + self.administrator_menu() + return + print("参与测试%d人" % student_num) + print("平均分:%0.2f" % (total / student_num)) + input("按任意键继续") + self.administrator_menu() + return + + def save_information(self): # 以字符串的数据类型向文件中写入 + with open("StudentInfo.txt", "w", encoding="utf_8") as fp: + for stu in self.StudentInfo: + fp.write(stu["用户名"]) + fp.write(",") + fp.write(stu["账号"]) + fp.write(",") + fp.write(stu["密码"]) + fp.write(",") + fp.write(stu["成绩"]) + fp.write(",") + fp.write(stu["答题时间"]) + fp.write(",") + fp.close() # 写入的时候数据之间用”,“分割开,读取的时候再用split函数分割分别读取 + with open("ProblemInfo.txt", "w", encoding="utf_8") as fp1: + for pro in self.ProblemInfo: + fp1.write(pro["题号"]) + fp1.write(",") + fp1.write(pro["题目"]) + fp1.write(",") + fp1.write(pro["选项A"]) + fp1.write(",") + fp1.write(pro["选项B"]) + fp1.write(",") + fp1.write(pro["选项C"]) + fp1.write(",") + fp1.write(pro["选项D"]) + fp1.write(",") + fp1.write(pro["正确答案"]) + fp1.write(",") + fp1.close() + return + + def read_information(self): + if not os.path.exists("StudentInfo.txt"): + print("暂无学生信息,跳过读取!") + else: + with open("StudentInfo.txt", "r", encoding="utf_8") as fp: + stu = fp.read() + stu = stu.split(",") # 文件的字符串split后变成列表类型,再通过列表循环读取,每次读取一批数据打包成一个字典,再append到程序当前存储信息的列表中 + stu.pop() + for i in range(len(stu) // 5): + stu_pass = {"用户名": stu[5 * i + 0], + "账号": stu[5 * i + 1], + "密码": stu[5 * i + 2], + "成绩": stu[5 * i + 3], + "答题时间": stu[5 * i + 4]} + self.StudentInfo.append(stu_pass) + fp.close() + print("学生信息读取成功!") + + if not os.path.exists("ProblemInfo.txt"): + print("暂无试卷信息,跳过读取!") + else: + with open("ProblemInfo.txt", "r", encoding="utf_8") as fp1: + pro = fp1.read() + pro = pro.split(",") + pro.pop() + for j in range(len(pro) // 7): + pro_pass = {"题号": pro[7 * j + 0], + "题目": pro[7 * j + 1], + "选项A": pro[7 * j + 2], + "选项B": pro[7 * j + 3], + "选项C": pro[7 * j + 4], + "选项D": pro[7 * j + 5], + "正确答案": pro[7 * j + 6]} + self.ProblemInfo.append(pro_pass) + fp1.close() + print("试卷信息读取成功!") + + +start = Manage() diff --git a/select.py b/select.py new file mode 100644 index 0000000..c91ab80 --- /dev/null +++ b/select.py @@ -0,0 +1,575 @@ +import time +import tkinter as tk +import SystemDesign + +start = SystemDesign.Manage() +start.read_information() + + +# root:主菜单 root2:管理员菜单 root3:管理员登录界面 root4:学生登陆界面 +def administrator_menu(): + root.withdraw() + root2 = tk.Tk() + root2.title("单项选择题答题与管理系统") + root2.geometry("900x700") + root2.config(background='lightblue') + bt1 = tk.Button(root2, text='1.录入试题信息', font=("Helvetica", 30), background='lightblue', + command=lambda: func_ad_1(root2)) + bt1.place(x=300, y=20) + bt2 = tk.Button(root2, text='2.查看学生信息', font=("Helvetica", 30), background='lightblue', + command=lambda: func_ad_2(root2)) + bt2.place(x=300, y=100) + bt3 = tk.Button(root2, text='3. 排名学生成绩', font=("Helvetica", 30), background='lightblue', + command=lambda: func_ad_3(root2)) + bt3.place(x=300, y=180) + bt4 = tk.Button(root2, text='4.查看试题信息', font=("Helvetica", 30), background='lightblue', + command=lambda: func_ad_4(root2)) + bt4.place(x=300, y=260) + bt5 = tk.Button(root2, text='5.分析总体答题情况', font=("Helvetica", 30), background='lightblue', + command=lambda: func_ad_5(root2)) + bt5.place(x=300, y=340) + bt6 = tk.Button(root2, text='6.删除试题信息', font=("Helvetica", 30), background='lightblue', + command=lambda: func_ad_6(root2)) + bt6.place(x=300, y=420) + bt7 = tk.Button(root2, text='7.删除学生信息', font=("Helvetica", 30), background='lightblue', + command=lambda: func_ad_7(root2)) + bt7.place(x=300, y=500) + bt8 = tk.Button(root2, text='8.返回上级', font=("Helvetica", 30), background='lightblue', + command=lambda: func_ad_8(root2)) + bt8.place(x=300, y=580) + + +def func_ad_1(x): # 管理员功能一 + x.destroy() + root_func1 = tk.Tk() + root_func1.title("单项选择题答题与管理系统") + root_func1.geometry("900x700") + root_func1.config(background='lightblue') + func1title = tk.Label(root_func1, text="输入你的试题信息:", font=("Helvetica", 40), background="lightblue") + func1title.pack() + func1title.place(x=220, y=80) + + func1_lb1 = tk.Label(root_func1, text="题号", font=("Helvetica", 20), background="lightblue") + func1_lb1.place(x=220, y=160) + func1_entry1 = tk.Entry(root_func1, width=45) + func1_entry1.place(x=320, y=170) + + func1_lb2 = tk.Label(root_func1, text="题目", font=("Helvetica", 20), background="lightblue") + func1_lb2.place(x=220, y=200) + func1_entry2 = tk.Entry(root_func1, width=45) + func1_entry2.place(x=320, y=210) + + func1_lb3 = tk.Label(root_func1, text="选项A", font=("Helvetica", 20), background="lightblue") + func1_lb3.place(x=210, y=240) + func1_entry3 = tk.Entry(root_func1, width=45) + func1_entry3.place(x=320, y=250) + + func1_lb4 = tk.Label(root_func1, text="选项B", font=("Helvetica", 20), background="lightblue") + func1_lb4.place(x=210, y=280) + func1_entry4 = tk.Entry(root_func1, width=45) + func1_entry4.place(x=320, y=290) + + func1_lb5 = tk.Label(root_func1, text="选项C", font=("Helvetica", 20), background="lightblue") + func1_lb5.place(x=210, y=320) + func1_entry5 = tk.Entry(root_func1, width=45) + func1_entry5.place(x=320, y=330) + + func1_lb6 = tk.Label(root_func1, text="选项D", font=("Helvetica", 20), background="lightblue") + func1_lb6.place(x=210, y=360) + func1_entry6 = tk.Entry(root_func1, width=45) + func1_entry6.place(x=320, y=370) + + func1_lb7 = tk.Label(root_func1, text="正确答案", font=("Helvetica", 20), background="lightblue") + func1_lb7.place(x=200, y=400) + func1_entry7 = tk.Entry(root_func1, width=45) + func1_entry7.place(x=320, y=410) + + func1_bt1 = tk.Button(root_func1, text="确定", font=("Helvetica", 20), background="lightblue", + command=lambda: func_ad_1_1(func1_entry1.get(), func1_entry2.get(), func1_entry3.get(), + func1_entry4.get(), func1_entry5.get(), func1_entry6.get(), + func1_entry7.get(), root_func1)) + func1_bt1.place(x=460, y=450) + + func1_bt2 = tk.Button(root_func1, text="取消", font=("Helvetica", 20), background="lightblue", + command=lambda: func_back(root_func1)) + func1_bt2.place(x=560, y=450) + + func1_bt3 = tk.Button(root_func1, text="<- 返回", font=("Helvetica", 20), background="lightblue", + command=lambda: func_back(root_func1)) + func1_bt3.place(x=20, y=10) + + +def func_ad_1_1(x1, x2, x3, x4, x5, x6, x7, root_func1): # 功能一的衍生函数 + root_func1.destroy() + new_problem = SystemDesign.Problem(num=x1, + question=x2, + choice_a=x3, + choice_b=x4, + choice_c=x5, + + choice_d=x6, + answer=x7) + temp = {"题号": new_problem.num, "题目": new_problem.question, "选项A": new_problem.choice_a, + "选项B": new_problem.choice_b, "选项C": new_problem.choice_c, "选项D": new_problem.choice_d, + "正确答案": new_problem.answer} + start.ProblemInfo.append(temp) + start.save_information() + message = tk.Tk() + message.geometry("400x150") + message.title("单项选择题答题与管理系统") + message_lb = tk.Label(message, text="添加成功!", font=("等线", 30)) + message_lb.config(fg="red") + message_lb.pack() + message_lb.place(x=100, y=20) + message_bt = tk.Button(message, text="返回", height=1, width=8, command=lambda: func_back(message)) + message_bt.place(x=150, y=95) + + +def func_back(x): + x.destroy() + administrator_menu() + + +def func_ad_2(x): + x.destroy() + root_func2 = tk.Tk() + root_func2.title("单项选择题答题与管理系统") + root_func2.geometry("800x600") + bt1 = tk.Button(root_func2, text="返回", width=600, font=("Helvetica", 20), command=lambda: func_back(root_func2)) + bt1.place(x=20,y=10) + bt1.pack() + frame_func2 = tk.Frame(root_func2) + frame_func2.pack() + scrollbar1 = tk.Scrollbar(frame_func2) + scrollbar1.pack(side="right", fill="y") + scrollbar2 = tk.Scrollbar(frame_func2, orient="horizontal") + scrollbar2.pack(side="bottom", fill="x") + list_func2 = tk.Listbox(frame_func2, selectmode='browse', width=500, height=20, font=("等线", 30), + xscrollcommand=scrollbar2.set, yscrollcommand=scrollbar1.set) + for stu in start.StudentInfo: + list_func2.insert("end", stu) + list_func2.pack() + scrollbar1.config(command=list_func2.yview) + scrollbar2.config(command=list_func2.xview) + + +def func_ad_3(r): + r.destroy() + root_func3 = tk.Tk() + root_func3.title("单项选择题答题与管理系统") + root_func3.geometry("800x600") + bt1 = tk.Button(root_func3, text="返回", width=600, font=("Helvetica", 20), command=lambda: func_back(root_func3)) + bt1.pack() + frame_func3 = tk.Frame(root_func3) + frame_func3.pack() + scrollbar1 = tk.Scrollbar(frame_func3) + scrollbar1.pack(side="right", fill="y") + scrollbar2 = tk.Scrollbar(frame_func3, orient="horizontal") + scrollbar2.pack(side="bottom", fill="x") + list_func3 = tk.Listbox(frame_func3, selectmode='browse', width=500, height=20, font=("等线", 30), + xscrollcommand=scrollbar2.set, yscrollcommand=scrollbar1.set) + tool = start.StudentInfo + for del_zero in tool: + if del_zero["成绩"] == "暂无成绩": + del_zero["成绩"] = -1 + temp = sorted(tool, key=lambda x: int(x["成绩"]), reverse=True) + list_stu = [] + for stu in temp: + if stu["成绩"] == -1: + stu["成绩"] = "暂无成绩" + stu_pass = {"用户名": stu["用户名"], + "成绩": stu["成绩"], + "答题用时": stu["答题时间"]} + list_stu.append(stu_pass) + for stu in list_stu: + list_func3.insert("end", stu) + + list_func3.pack() + scrollbar1.config(command=list_func3.yview) + scrollbar2.config(command=list_func3.xview) + + +def func_ad_4(x): + x.destroy() + root_func4 = tk.Tk() + root_func4.title("单项选择题答题与管理系统") + root_func4.geometry("800x600") + bt1 = tk.Button(root_func4, text="返回", width=600, font=("Helvetica", 20), command=lambda: func_back(root_func4)) + bt1.pack() + frame_func4 = tk.Frame(root_func4) + frame_func4.pack() + scrollbar1 = tk.Scrollbar(frame_func4) + scrollbar1.pack(side="right", fill="y") + scrollbar2 = tk.Scrollbar(frame_func4, orient="horizontal") + scrollbar2.pack(side="bottom", fill="x") + list_func2 = tk.Listbox(frame_func4, selectmode='browse', width=500, height=20, font=("等线", 30), + xscrollcommand=scrollbar2.set, yscrollcommand=scrollbar1.set) + for stu in start.ProblemInfo: + list_func2.insert("end", stu) + list_func2.pack() + scrollbar1.config(command=list_func2.yview) + scrollbar2.config(command=list_func2.xview) + + +def func_ad_5(x): + x.destroy() + root_func5 = tk.Tk() + root_func5.title("单项选择题答题与管理系统") + root_func5.geometry("800x600") + root_func5.config(background="lightblue") + bt1 = tk.Button(root_func5, text="返回", width=600, font=("Helvetica", 20), command=lambda: func_back(root_func5)) + bt1.pack() + lb1 = tk.Label(root_func5, background="lightblue", text="本次测试有%d道题目" % len(start.ProblemInfo), + font=("Helvetica", 40)) + lb1.pack() + lb2 = tk.Label(root_func5, background="lightblue", text="满分%d分" % (len(start.ProblemInfo) * 5), + font=("Helvetica", 40)) + lb2.pack() + student_num = 0 + total = 0 + for stu in start.StudentInfo: + if stu["成绩"] == "暂无成绩": + continue + total += int(stu["成绩"]) + student_num += 1 + lb3 = tk.Label(root_func5, background="lightblue", text="参与测试%d人" % student_num, font=("Helvetica", 40)) + lb3.pack() + lb3 = tk.Label(root_func5, background="lightblue", text="平均分:%0.2f" % (total / student_num), font=("Helvetica", 40)) + lb3.pack() + + +def func_ad_6(x): + x.destroy() + root_func6 = tk.Tk() + root_func6.geometry("600x300") + root_func6.title("单项选择题答题与管理系统") + lb_func6 = tk.Label(root_func6, text="请输入要删除的试题题号!", font=("Helvetica", 20)) + lb_func6.pack() + entry_func6 = tk.Entry(root_func6) + entry_func6.place(x=220, y=60) + bt1 = tk.Button(root_func6, height=1, width=8, text="确认", + command=lambda: func_ad_6_1(entry_func6.get())) + bt1.place(x=220, y=100) + bt2 = tk.Button(root_func6, height=1, width=8, text="取消", command=lambda: func_back(root_func6)) + bt2.place(x=300, y=100) + + +def func_ad_6_1(x): + index = 0 + for pro in start.ProblemInfo: + if pro["题号"] == x: + del start.ProblemInfo[index] + start.save_information() + message = tk.Tk() + message.geometry("400x150") + message.title("单项选择题答题与管理系统") + message_lb = tk.Label(message, text="删除成功!", font=("等线", 30)) + message_lb.config(fg="red") + message_lb.pack() + message_bt = tk.Button(message, text="返回", height=1, width=8, command=message.destroy) + message_bt.place(x=150, y=75) + return + index += 1 + message = tk.Tk() + message.geometry("400x150") + message.title("单项选择题答题与管理系统") + message_lb = tk.Label(message, text="未找到试题信息", font=("等线", 30)) + message_lb.config(fg="red") + message_lb.pack() + message_bt = tk.Button(message, text="返回", height=1, width=8, command=message.destroy) + message_bt.place(x=150, y=75) + + +def func_ad_7(x): + x.destroy() + root_func7 = tk.Tk() + root_func7.geometry("600x300") + root_func7.title("单项选择题答题与管理系统") + lb_func7 = tk.Label(root_func7, text="请输入要删除的学生账号!", font=("Helvetica", 20)) + lb_func7.pack() + entry_func7 = tk.Entry(root_func7) + entry_func7.place(x=220, y=60) + bt1 = tk.Button(root_func7, height=1, width=8, text="确认", + command=lambda: func_ad_7_1(entry_func7.get())) + bt1.place(x=220, y=100) + bt2 = tk.Button(root_func7, height=1, width=8, text="取消", command=lambda: func_back(root_func7)) + bt2.place(x=300, y=100) + + +def func_ad_7_1(x): + index = 0 + for pro in start.StudentInfo: + if pro["账号"] == x: + del start.StudentInfo[index] + start.save_information() + message = tk.Tk() + message.geometry("400x150") + message.title("单项选择题答题与管理系统") + message_lb = tk.Label(message, text="删除成功!", font=("等线", 30)) + message_lb.config(fg="red") + message_lb.pack() + message_bt = tk.Button(message, text="返回", height=1, width=8, command=message.destroy) + message_bt.place(x=150, y=75) + return + index += 1 + message = tk.Tk() + message.geometry("400x150") + message.title("单项选择题答题与管理系统") + message_lb = tk.Label(message, text="未找到学生信息", font=("等线", 30)) + message_lb.config(fg="red") + message_lb.pack() + message_bt = tk.Button(message, text="返回", height=1, width=8, command=message.destroy) + message_bt.place(x=150, y=75) + + +def func_ad_8(x): + x.destroy() + root.deiconify() + + +def student_menu(x): + index = 0 + global grade + grade = 0 + start_time = time.time() + root.withdraw() + root_stu = tk.Tk() + root_stu.title("单项选择题答题与管理系统") + root_stu.geometry("900x700") + root_stu.config(background='lightblue') + lb1 = tk.Label(root_stu, text="欢迎你%s同学" % x, font=("Helvetica", 40), background='lightblue') + lb1.pack() + bt1 = tk.Button(root_stu, text='1.开始答题', font=("Helvetica", 30), background='lightblue', + command=lambda: func_stu_1(root_stu, x, index, start_time)) + bt1.place(x=320, y=240) + bt2 = tk.Button(root_stu, text='2.返回上级', font=("Helvetica", 30), background='lightblue', + command=lambda: func_stu_2(root_stu)) + bt2.place(x=320, y=360) + + +def func_stu_1(win, name, index_pro, start_time): + win.destroy() + root_func1 = tk.Tk() + root_func1.title("单项选择题答题与管理系统") + root_func1.geometry("900x700") + root_func1.config(background='lightblue') + func1title = tk.Label(root_func1, text="做下一题前请先提交当前题目!", font=("Helvetica", 40), background="lightblue") + func1title.pack() + + temp = start.ProblemInfo[index_pro] + + pro_num = tk.Label(root_func1, text="%s." % temp["题号"], font=("Helvetica", 30), background="lightblue", ) + pro_num.place(x=200, y=80) + + pro_question = tk.Label(root_func1, text="%s" % temp["题目"], font=("Helvetica", 30), background="lightblue") + pro_question.place(x=260, y=80) + + pro_a = tk.Label(root_func1, text="A.%s" % temp["选项A"], font=("Helvetica", 30), background="lightblue") + pro_a.place(x=220, y=160) + + pro_b = tk.Label(root_func1, text="B.%s" % temp["选项B"], font=("Helvetica", 30), background="lightblue") + pro_b.place(x=220, y=240) + + pro_c = tk.Label(root_func1, text="C.%s" % temp["选项C"], font=("Helvetica", 30), background="lightblue") + pro_c.place(x=220, y=320) + + pro_d = tk.Label(root_func1, text="D.%s" % temp["选项D"], font=("Helvetica", 30), background="lightblue") + pro_d.place(x=220, y=400) + + pro_answer = tk.Label(root_func1, text="你的选项为", font=("Helvetica", 30), background="lightblue") + pro_answer.place(x=220, y=480) + answer_get = tk.Entry(root_func1, font=("Helvetica", 30), width=2) + answer_get.place(x=450, y=480) + + bt_ensure = tk.Button(root_func1, text="提 交", command=lambda: check_answer(answer_get.get(), temp["正确答案"]), + font=("Helvetica", 30), background="lightblue") + bt_ensure.place(x=220, y=560) + + if index_pro == len(start.ProblemInfo) - 1: # 目前只能下一题,且无法返回更改 + for stu in start.StudentInfo: + if stu["用户名"] == name: + stu["成绩"] = str(grade) + stu["答题时间"] = str(int(time.time() - start_time)) + start.save_information() + bt_end = tk.Button(root_func1, text="结束考试", command=lambda: func_stu_1_1(root_func1), + font=("Helvetica", 30), background="lightblue") + bt_end.place(x=480, y=560) + + else: + bt_down = tk.Button(root_func1, text="下一题", + command=lambda: func_stu_1(root_func1, name, index_pro + 1, start_time), + font=("Helvetica", 30), + background="lightblue") + bt_down.place(x=480, y=560) + + +def check_answer(x, y): + global grade + if x == y: + grade += 5 + + +def func_stu_1_1(x): + x.destroy() + message = tk.Tk() + message.geometry("400x150") + message.title("单项选择题答题与管理系统") + message_lb = tk.Label(message, text="答题结束!", font=("等线", 30)) + message_lb.config(fg="red") + message_lb.pack() + message_bt = tk.Button(message, text="返回", height=1, width=8, command=lambda: func_stu_2(message)) + message_bt.place(x=150, y=75) + + +def func_stu_1_2(x): + x.destroy() + root.deiconify() + + +def func_stu_2(x): + x.destroy() + root.deiconify() + + +def check_psw(x, y): + if x == "123456": + y.destroy() + administrator_menu() + else: + message = tk.Tk() + message.geometry("300x150") + message.title("单项选择题答题与管理系统") + message_lb = tk.Label(message, text="密码错误!", font=("等线", 30)) + message_lb.config(fg="red") + message_lb.pack() + message_bt = tk.Button(message, text="返回", height=1, width=8, command=message.destroy) + message_bt.place(x=120, y=75) + + +def administrator_login(): + root3 = tk.Tk() + root3.geometry("600x300") + root3.title("单项选择题答题与管理系统") + ad_login = tk.Label(root3, text="请输入管理员密码!", font=("Helvetica", 20)) + ad_login.pack() + ad_login_entry = tk.Entry(root3, show="*") + ad_login_entry.place(x=220, y=60) + ad_login_bt1 = tk.Button(root3, height=1, width=8, text="确认", + command=lambda: check_psw(ad_login_entry.get(), root3)) + ad_login_bt1.place(x=220, y=100) + ad_login_bt2 = tk.Button(root3, height=1, width=8, text="取消", command=root3.destroy) + ad_login_bt2.place(x=300, y=100) + + +def student_login(): + root4 = tk.Tk() + root4.geometry("600x300") + root4.title("单项选择题答题与管理系统") + st_login = tk.Label(root4, text="请输入账号和密码!", font=("Helvetica", 20)) + st_login.pack() + st_lb1 = tk.Label(root4, text="账号", font=6) + st_lb1.place(x=200, y=60) + st_login_entry1 = tk.Entry(root4) + st_login_entry1.place(x=250, y=60) + st_lb2 = tk.Label(root4, text="密码", font=6) + st_lb2.place(x=200, y=100) + st_login_entry2 = tk.Entry(root4) + st_login_entry2.place(x=250, y=100) + st_login_bt1 = tk.Button(root4, height=1, width=8, text="确认", + command=lambda: student_check(st_login_entry1.get(), st_login_entry2.get(), root4)) + st_login_bt1.place(x=240, y=130) + st_login_bt2 = tk.Button(root4, height=1, width=8, text="取消", command=root4.destroy) + st_login_bt2.place(x=320, y=130) + ''' + bt2 = tk.Button(root, text='1.开始答题', font=("Helvetica", 30), background='lightblue') + bt2.place(x=300, y=180) + bt3 = tk.Button(root, text='2.返回上级', font=("Helvetica", 30), background='lightblue') + bt3.place(x=300, y=260) + ''' + + +def student_check(x, y, z): # 检查学生的登录信息 + for stu in start.StudentInfo: + if x == stu["账号"] and y == stu["密码"]: + z.destroy() + student_menu(stu["用户名"]) + break + else: + message = tk.Tk() + message.geometry("400x150") + message.title("单项选择题答题与管理系统") + message_lb = tk.Label(message, text="账号或密码错误!", font=("等线", 30)) + message_lb.config(fg="red") + message_lb.pack() + message_bt = tk.Button(message, text="返回", height=1, width=8, command=message.destroy) + message_bt.place(x=150, y=75) + + +def student_register(): # 注册学生信息页面 + root5 = tk.Tk() + root5.geometry("600x300") + root5.title("单项选择题答题与管理系统") + st_login = tk.Label(root5, text="填写你的注册信息", font=("Helvetica", 20)) + st_login.pack() + + st_lb1 = tk.Label(root5, text="用户名", font=6) + st_lb1.place(x=185, y=60) + st_login_entry1 = tk.Entry(root5) + st_login_entry1.place(x=250, y=60) + + st_lb2 = tk.Label(root5, text="账号", font=6) + st_lb2.place(x=200, y=100) + st_login_entry2 = tk.Entry(root5) + st_login_entry2.place(x=250, y=100) + + st_lb2 = tk.Label(root5, text="密码", font=6) + st_lb2.place(x=200, y=140) + st_login_entry3 = tk.Entry(root5) + st_login_entry3.place(x=250, y=140) + + st_login_bt1 = tk.Button(root5, height=1, width=8, text="确认", + command=lambda: add_student(st_login_entry1.get(), st_login_entry2.get(), + st_login_entry3.get(), root5)) + st_login_bt1.place(x=240, y=180) + st_login_bt2 = tk.Button(root5, height=1, width=8, text="取消", command=root5.destroy) + st_login_bt2.place(x=320, y=180) + + +def add_student(x, y, z, root5): # 注册成功后的消息弹窗页面 + root5.destroy() + new_student = SystemDesign.Student(name=x, + user_name=y, + user_password=z, + grade="暂无成绩", + usetime="暂无信息") + temp = {"用户名": new_student.name, "账号": new_student.user_name, "密码": new_student.user_password, + "成绩": new_student.grade, "答题时间": new_student.usetime} + # 这里的new_student不能直接传入列表,要放在一个字典里把数据”打包“过去 + start.StudentInfo.append(temp) + start.save_information() + message = tk.Tk() + message.geometry("400x150") + message.title("单项选择题答题与管理系统") + message_lb = tk.Label(message, text="添加成功!", font=("等线", 30)) + message_lb.config(fg="red") + message_lb.pack() + message_bt = tk.Button(message, text="返回", height=1, width=8, command=message.destroy) + message_bt.place(x=150, y=75) + + +root = tk.Tk() +root.title("单项选择题答题与管理系统") +root.geometry("900x600") +root.config(background='lightblue') +main_label1 = tk.Label(root, text='单项选择题答题与管理系统', font=("Helvetica", 40), background='lightblue') +main_label1.pack() +main_bt1 = tk.Button(root, text='1.管理员登录', font=("Helvetica", 30), background='lightblue', command=administrator_login) +main_bt1.place(x=300, y=100) +main_bt2 = tk.Button(root, text='2.学生端登录', font=("Helvetica", 30), background='lightblue', command=student_login) +main_bt2.place(x=300, y=180) +main_bt3 = tk.Button(root, text='3. 注册学生账户', font=("Helvetica", 30), background='lightblue', command=student_register) +main_bt3.place(x=300, y=260) +main_bt4 = tk.Button(root, text='4.退出系统', font=("Helvetica", 30), background='lightblue', command=exit) +main_bt4.place(x=300, y=340) +global grade +root.mainloop()