You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

576 lines
24 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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()