From dc3b153520e5a3f879102cc289d0f56a73d2a799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8E=9F=E6=B3=BD?= <2200729686@qq.com> Date: Fri, 25 Nov 2022 16:55:40 +0800 Subject: [PATCH] add --- src/AdScreen.py | 1208 ++++++++++++++++++++++++++++++++++++++++++++ src/LoginScreen.py | 101 ++++ src/StuScreen.py | 597 ++++++++++++++++++++++ 3 files changed, 1906 insertions(+) create mode 100644 src/AdScreen.py create mode 100644 src/LoginScreen.py create mode 100644 src/StuScreen.py diff --git a/src/AdScreen.py b/src/AdScreen.py new file mode 100644 index 0000000..d17f4e2 --- /dev/null +++ b/src/AdScreen.py @@ -0,0 +1,1208 @@ +import tkinter +from tkinter import * + +from tkinter import messagebox +from tkinter.ttk import Treeview + +import pymysql + + +class AdSc: + def __init__(self, master, no): + self.id = no + self.i = 1 + self.course_array = [] + self.AllQues_array = [] + self.Ques_array = [] + self.root = master + + self.root.geometry('1000x500') + self.root.title('管理员主页') + self.window = Frame(self.root) + self.window.pack() + self.menubar = Menu(self.window) + self.menubar.add_cascade(label="管理科目", command=self.Man_Course) + + self.ManPapmenu = Menu(self.menubar, tearoff=False) + # self.menubar.add_command(label="生成试卷", command=self.Mak_A_Paper) + # self.menubar.add_command(label="管理试题", command=self.Man_Ques) + # self.menubar.add_cascade(label="管理试题", menu=self.ManPapmenu) + self.menubar.add_command(label="生成试卷", command=self.Mak_A_Paper) + self.menubar.add_command(label="管理试题", command=self.Man_Ques) + + self.ManGramenu = Menu(self.menubar, tearoff=False) + + self.menubar.add_cascade(label="管理学生成绩", menu=self.ManGramenu) + + self.menubar.add_command(label="修改密码", command=self.Change_Pw) + + self.menubar.add_command(label="留言系统", command=self.SomeMessage) + + # self.ManPapmenu.add_command(label="增加试题", command=self.Add_Ques) + # self.ManPapmenu.add_command(label="删除试题", command=self.Del_Ques) + self.ManGramenu.add_command(label="查询成绩", command=self.Res_Score) + + self.ManGramenu.add_command(label="录入成绩", command=self.Checkin_Gra) + self.root.config(menu=self.menubar) + + def Man_Course(self): # 管理科目按钮触发函数 + self.window.pack_forget() + self.window = Frame(self.root) + self.window.pack() + Label(self.window, text='请输入课程编号:', font=('宋体', 15)).pack(pady=10) + self.countVar = StringVar() + self.CourseIDinput = Entry(self.window, textvariable=self.countVar) + self.CourseIDinput.pack() + Label(self.window, text='请输入课程名称:', font=('宋体', 15)).pack(pady=10) + self.countVar = StringVar() + self.CourseNameinput = Entry(self.window, textvariable=self.countVar) + self.CourseNameinput.pack() + Button(self.window, text='添加', width=13, command=self.Add_Course_Confirm, font=('宋体', 15)).pack(pady=10) + Button(self.window, text='删除', width=13, command=self.Del_Course_Confirm, font=('宋体', 15)).pack(pady=10) + main_panedwindow = PanedWindow(self.window, sashrelief=RAISED, sashwidth=5, orient=VERTICAL) + + + # 课程列表区 + course_list_frame = Frame() + course_list_sub_frame = Frame(course_list_frame) + self.course_list_tree = Treeview(course_list_sub_frame, selectmode='browse') + self.course_list_tree.bind('<>') + + + # 课程列表垂直滚动条 + course_list_vscrollbar = Scrollbar(course_list_sub_frame, orient="vertical", command=self.course_list_tree.yview) + course_list_vscrollbar.pack(side=RIGHT, fill=Y, expand=YES) + self.course_list_tree.configure(yscrollcommand=course_list_vscrollbar.set) + course_list_sub_frame.pack(side=TOP, fill=BOTH, expand=YES) + + + # 课程列表水平滚动条 + course_list_hscrollbar = Scrollbar(course_list_frame, orient="horizontal", command=self.course_list_tree.xview) + course_list_hscrollbar.pack(side=BOTTOM, fill=X, expand=YES) + self.course_list_tree.configure(xscrollcommand=course_list_hscrollbar.set) + + + # 课程列表区列标题 + self.course_list_tree["columns"] = ("CourseID", "CourseName", "AdID") + course_list_column_width = [333, 333, 333] + self.course_list_tree['show'] = 'headings' + + + # 载入列标题 + for column_name, column_width in zip(self.course_list_tree["columns"], course_list_column_width): + self.course_list_tree.column(column_name, width=column_width, anchor='w') + self.course_list_tree.heading(column_name, text=column_name) + self.course_list_tree.pack(side=LEFT, fill=X, expand=YES) + course_list_frame.pack(side=TOP, fill=X, padx=5, pady=5, expand=YES, anchor='n') + + + # 将数据包列表区加入到主窗体 + main_panedwindow.add(course_list_frame) + main_panedwindow.pack() + conn = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8') + cur = conn.cursor() + search_sqi = "select * from Course;" + cur.execute(search_sqi) + + i = 1 + for row in cur: + self.course_list_tree.insert("", "end", str(i), values=row) + i = i + 1 + self.course_array.append(row) + self.course_list_tree.update_idletasks() + cur.close() + conn.close() + + def Add_Course_Confirm(self): # 添加科目按钮触发函数 + a = self.CourseIDinput.get() + b = self.CourseNameinput.get() + + if len(a) == 0 or len(b) == 0: + tkinter.messagebox.showerror(title='警告', message='课程编号或课程名称不能为空') + else: + conn = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8') + cur = conn.cursor() + search_sqi = "select CourseID from Course where CourseID= \"" + a + "\";" + cur.execute(search_sqi) + info = cur.fetchone() + search_sqi = "select CourseName from Course where CourseName= \"" + b + "\";" + cur.execute(search_sqi) + info1 = cur.fetchone() + + if info is None and info1 is None: + search_sqi = "insert into Course values(\"" + a + "\",\"" + b + "\",\"" + self.id + "\");" + cur.execute(search_sqi) + conn.commit() + self.course_array.append([a, b, self.id]) + tkinter.messagebox.showinfo(title='提示', message='添加成功') + self.course_list_tree.insert("", "end", str(len(self.course_array)), values=self.course_array[-1]) + self.course_list_tree.update_idletasks() + else: + tkinter.messagebox.showerror(title='警告', message='已有该课程编号或课程名称') + cur.close() + conn.close() + # def Del_Course_Confirm(self): # 删除科目触发函数 + # course_id = self.course_array[int(self.course_list_tree.selection()[0])-1][0] + # conn = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8') + # cur = conn.cursor() + # search_sqi = "select AdID from Course where CourseID=\"" + course_id + "\";" + # cur.execute(search_sqi) + # info = cur.fetchone() + # if info[0] == self.id: + # search_sqi = "DELETE FROM Course WHERE CourseID=\"" + course_id + "\";" + # cur.execute(search_sqi) + # conn.commit() + # self.course_list_tree.delete(self.course_list_tree.selection()[0]) + # tkinter.messagebox.showinfo(title='提示', message='删除成功') + # else: + # tkinter.messagebox.showerror(title='警告', message='只能删除自己添加的科目') + # cur.close() + # conn.close() + def Del_Course_Confirm(self): # 删除科目触发函数 + course_id = self.course_array[int(self.course_list_tree.selection()[0])-1][0] + + conn = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8') + cur = conn.cursor() + search_sqi = "select AdID from Course where CourseID=\"" + course_id + "\";" + cur.execute(search_sqi) + info = cur.fetchone() + + if info[0] == self.id: + search_sqi = "DELETE FROM Course WHERE CourseID=\"" + course_id + "\";" + cur.execute(search_sqi) + conn.commit() + self.course_list_tree.delete(self.course_list_tree.selection()[0]) + tkinter.messagebox.showinfo(title='提示', message='删除成功') + + else: + tkinter.messagebox.showerror(title='警告', message='只能删除自己添加的科目') + + cur.close() + conn.close() + + def Man_Ques(self): # 管理试题触发函数 + # self.window.pack_forget() + # self.window = Frame(self.root) + # self.window.pack() + # main_panedwindow = PanedWindow(self.window, sashrelief=RAISED, sashwidth=5, orient=VERTICAL) + # ff = Frame() + self.window.pack_forget() + self.window = Frame(self.root) + self.window.pack() + main_panedwindow = PanedWindow(self.window, sashrelief=RAISED, sashwidth=5, orient=VERTICAL) + + ff = Frame() + + Label(ff, text='请输入试题编号:', font=('宋体', 15)).grid(row=0, column=0, padx=5, pady=10) + self.countVar = StringVar() + self.QuesIDinput = Entry(ff, textvariable=self.countVar) + self.QuesIDinput.grid(row=0, column=1, padx=5, pady=5) + + Label(ff, text='请输入试题内容:', font=('宋体', 15)).grid(row=0, column=4, padx=5, pady=10) + self.countVar = StringVar() + self.QuesContentinput = Entry(ff, textvariable=self.countVar) + self.QuesContentinput.grid(row=0, column=5, padx=5, pady=5) + + + Label(ff, text='请输入选项1:', font=('宋体', 15)).grid(row=1, column=0, padx=5, pady=10) + self.countVar = StringVar() + self.option1input = Entry(ff, textvariable=self.countVar) + self.option1input.grid(row=1, column=1, padx=5, pady=10) + + Label(ff, text='请输入选项2:', font=('宋体', 15)).grid(row=1, column=4, padx=5, pady=10) + self.countVar = StringVar() + self.option2input = Entry(ff, textvariable=self.countVar) + self.option2input.grid(row=1, column=5, padx=5, pady=5) + + Label(ff, text='请输入选项3:', font=('宋体', 15)).grid(row=2, column=0, padx=5, pady=10) + self.countVar = StringVar() + self.option3input = Entry(ff, textvariable=self.countVar) + self.option3input.grid(row=2, column=1, padx=5, pady=5) + + Label(ff, text='请输入选项4:', font=('宋体', 15)).grid(row=2, column=4, padx=5, pady=10) + self.countVar = StringVar() + self.option4input = Entry(ff, textvariable=self.countVar) + self.option4input.grid(row=2, column=5, padx=5, pady=5) + + Label(ff, text='请输入答案:', font=('宋体', 15)).grid(row=3, column=0, padx=5, pady=10) + self.countVar = StringVar() + self.answerinput = Entry(ff, textvariable=self.countVar) + self.answerinput.grid(row=3, column=1, padx=5, pady=5) + + Label(ff, text='请输入试题所属科目:', font=('宋体', 15)).grid(row=3, column=4, padx=5, pady=10) + self.countVar = StringVar() + self.CourseIDinput = Entry(ff, textvariable=self.countVar) + self.CourseIDinput.grid(row=3, column=5, padx=5, pady=5) + Button(ff, text='添加', width=10, command=self.Add_Ques_Confirm, font=('宋体', 15)).grid(row=4, column=2, + padx=5, + pady=10) + Button(ff, text='删除', width=10, command=self.Del_Ques_Confirm, font=('宋体', 15)).grid(row=4, column=3, + padx=5, + pady=10) + main_panedwindow.add(ff) + # 题目列表区 + Ques_list_frame = Frame() + Ques_list_sub_frame = Frame(Ques_list_frame) + self.Ques_list_tree = Treeview(Ques_list_sub_frame, selectmode='browse') + self.Ques_list_tree.bind('<>') + + + # 题目列表垂直滚动条 + Ques_list_vscrollbar = Scrollbar(Ques_list_sub_frame, orient="vertical", + command=self.Ques_list_tree.yview) + + Ques_list_vscrollbar.pack(side=RIGHT, fill=Y, expand=YES) + self.Ques_list_tree.configure(yscrollcommand=Ques_list_vscrollbar.set) + Ques_list_sub_frame.pack(side=TOP, fill=BOTH, expand=YES) + + + # 题目列表水平滚动条 + Ques_list_hscrollbar = Scrollbar(Ques_list_frame, orient="horizontal", command=self.Ques_list_tree.xview) + Ques_list_hscrollbar.pack(side=BOTTOM, fill=X, expand=YES) + self.Ques_list_tree.configure(xscrollcommand=Ques_list_hscrollbar.set) + + + # 题目列表区列标题 + self.Ques_list_tree["columns"] = ("QuesID", "QuesContent", "CourseID") + Ques_list_column_width = [310, 310, 310] + self.Ques_list_tree['show'] = 'headings' + + + # 载入列标题 + for column_name, column_width in zip(self.Ques_list_tree["columns"], Ques_list_column_width): + self.Ques_list_tree.column(column_name, width=column_width, anchor='w') + self.Ques_list_tree.heading(column_name, text=column_name) + self.Ques_list_tree.pack(side=LEFT, fill=X, expand=YES) + Ques_list_frame.pack(side=TOP, fill=X, padx=5, pady=5, expand=YES, anchor='n') + + + # 将题目列表区加入到主窗体 + main_panedwindow.add(Ques_list_frame) + main_panedwindow.pack() + + conn = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8') + cur = conn.cursor() + search_sqi = "select * from questions;" + # main_panedwindow.add(Ques_list_frame) + # main_panedwindow.pack() + # + # conn = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8') + # cur = conn.cursor() + # search_sqi = "select * from questions;" + cur.execute(search_sqi) + i = 1 + for row in cur: + self.Ques_list_tree.insert("", "end", str(i), values=(row[0], row[2], row[1])) + i = i + 1 + self.Ques_array.append(row) + self.Ques_list_tree.update_idletasks() + cur.close() + conn.close() + + def Add_Ques_Confirm(self): # 添加试题按钮确定触发函数 + a = self.QuesIDinput.get() + + b = self.QuesContentinput.get() + + c = self.option1input.get() + + d = self.option2input.get() + e = self.option3input.get() + f = self.option4input.get() + g = self.answerinput.get() + h = self.CourseIDinput.get() + + conn = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8') + cur = conn.cursor() + search_sqi = "select * from course where CourseID=\"" + h + "\";" + cur.execute(search_sqi) + info = cur.fetchone() + + if info is None: + messagebox.showerror(title="提示", message="科目编码不能为空") + + elif len(a) == 0: + messagebox.showerror(title="提示", message="试题编码不能为空") + + elif g != 'A' and g != 'B' and g != 'C' and g != 'D': + messagebox.showerror(title="提示", message="试题答案应为ABCD其中一个") + + else: + search_sqi = "insert into questions values(\"" + a + "\",\"" + h + "\",\"" + b + "\",\"" + c + "\",\"" + d + "\",\"" + e + "\",\"" + f + "\",\"" + g + "\");" + cur.execute(search_sqi) + self.Ques_list_tree.insert("", "end", str(len(self.Ques_array) + 1), values=(a, b, h)) + messagebox.showinfo(title="提示", message="添加成功!") + self.Ques_array.append((a, h, b, c, d, e, f, g)) + self.Ques_list_tree.update_idletasks() + conn.commit() + cur.close() + conn.close() + + def Del_Ques_Confirm(self): # 删除试题按钮确定触发函数 + # self.a = self.QuesIDinput.get() + # self.b = self.CourseIDinput.get() + + a = self.Ques_array[int(self.Ques_list_tree.selection()[0]) - 1][0] + b = self.Ques_array[int(self.Ques_list_tree.selection()[0]) - 1][1] + + # print(self.Ques_array) + # 以下数据库内容需修改 + + conn = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8') + cur = conn.cursor() + + search_sqil = "DELETE FROM questions WHERE QuesId=\"" + a + "\" and CourseId=\"" + b + "\";" + self.Ques_list_tree.delete(self.Ques_list_tree.selection()[0]) + messagebox.showinfo(title="提示", message="删除成功!") + cur.execute(search_sqil) + + conn.commit() + + cur.close() + + conn.close() + + def Res_Score(self): # 查询成绩按钮触发函数 + self.window.pack_forget() + self.window = Frame(self.root) + self.window.pack() + + Label(self.window, text='请输入学生编号', font=('宋体', 15)).pack(pady=10) + self.countVar = StringVar() + self.studentIDinput = Entry(self.window, textvariable=self.countVar,) + self.studentIDinput.pack(pady=10) + + Button(self.window, text='查询', width=14,command=self.Res_Score_Confirm, height=1, font=('宋体', 15)).pack(pady=10) + main_panedwindow = PanedWindow(self.window, sashrelief=RAISED, sashwidth=5, orient=VERTICAL) + + # 科目列表区 + course_list_frame = Frame() + course_list_sub_frame = Frame(course_list_frame) + self.course_list_tree = Treeview(course_list_sub_frame, selectmode='browse') + self.course_list_tree.bind('<>') + + + # 科目列表垂直滚动条 + course_list_vscrollbar = Scrollbar(course_list_sub_frame, orient="vertical", command=self.course_list_tree.yview) + course_list_vscrollbar.pack(side=RIGHT, fill=Y, expand=YES) + self.course_list_tree.configure(yscrollcommand=course_list_vscrollbar.set) + course_list_sub_frame.pack(side=TOP, fill=BOTH, expand=YES) + + + # 课程列表水平滚动条 + course_list_hscrollbar = Scrollbar(course_list_frame, orient="horizontal", command=self.course_list_tree.xview) + course_list_hscrollbar.pack(side=BOTTOM, fill=X, expand=YES) + self.course_list_tree.configure(xscrollcommand=course_list_hscrollbar.set) + + + # 课程列表区列标题 + self.course_list_tree["columns"] = ('ExamName', 'grade', 'beginTime', 'endTime') + course_list_column_width = [250, 250, 250, 250] + self.course_list_tree['show'] = 'headings' + + + # 载入列标题 + for column_name, column_width in zip(self.course_list_tree["columns"], course_list_column_width): + self.course_list_tree.column(column_name, width=column_width, anchor='w') + self.course_list_tree.heading(column_name, text=column_name) + self.course_list_tree.pack(side=LEFT, fill=X, expand=YES) + course_list_frame.pack(side=TOP, fill=X, padx=5, pady=5, expand=YES, anchor='n') + # 将数据包列表区加入到主窗体 + main_panedwindow.add(course_list_frame) + main_panedwindow.pack() + # 此处缺失所有科目名称 + + def Res_Score_Confirm(self): # 查询成绩确定触发函数 + # 以下数据库内容需修改 + selection_item = self.course_list_tree.get_children() + if not(selection_item is None): + for i in selection_item: + self.course_list_tree.delete(i) + self.course_list_tree.update_idletasks() + a = self.studentIDinput.get() + conn = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8') + cur = conn.cursor() + search_sqi = "select studentId from student where studentId=\"" + a + "\";" + cur.execute(search_sqi) + info = cur.fetchone() + if info is None: + tkinter.messagebox.showerror(title='警告', message='暂无此学生') + else: + search_sqi = "select ExamName,grade,beginTime,endTime from studentscore where studentId=\"" + a + "\";" + cur.execute(search_sqi) + i = 1 + for row in cur: + self.course_list_tree.insert("", "end", str(i), values=row) + i = i + 1 + self.course_list_tree.update_idletasks() + cur.close() + conn.close() + + def Checkin_Gra(self): + # 录入成绩按钮触发函数 + self.window.pack_forget() + self.window = Frame(self.root) + self.window.pack() + + + Label(self.window, text='请输入学生编号:', font=('宋体', 15)).grid(row=0, column=0, padx=15, pady=25) + self.countVar = StringVar() + self.studentIDinput = Entry(self.window, textvariable=self.countVar) + self.studentIDinput.grid(row=0, column=1) + + + Label(self.window, text='请输入考试名称:', font=('宋体', 15)).grid(row=1, column=0, padx=15, pady=25) + self.countVar = StringVar() + self.ExamNameinput = Entry(self.window, textvariable=self.countVar) + self.ExamNameinput.grid(row=1, column=1) + + # Label(self.window, text='请输入成绩:', font=('宋体', 15)).grid(row=2, column=0, padx=15, pady=25) + # self.countVar = StringVar() + # self.gradeinput = Entry(self.window, textvariable=self.countVar) + # self.gradeinput.grid(row=2, column=1) + + + Label(self.window, text='请输入成绩:', font=('宋体', 15)).grid(row=2, column=0, padx=15, pady=25) + self.countVar = StringVar() + self.gradeinput = Entry(self.window, textvariable=self.countVar) + self.gradeinput.grid(row=2, column=1) + + + Button(self.window, text='录入', width=14, command=self.Checkin_Gra_Confirm, + font=('宋体', 15)).grid(row=3, column=0, padx=15, pady=25) + + + def Checkin_Gra_Confirm(self): # 录入成绩确定触发函数 + a = self.studentIDinput.get() + + b = self.ExamNameinput.get() + + c = self.gradeinput.get() + + + # 以下数据库内容需修改 + conn = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8' + ) + cur = conn.cursor() + search_sqi = "select studentId from student where studentId=\"" + a + "\";" + cur.execute(search_sqi) + info = cur.fetchone() + search_sqi = "select ExamName from examnation where ExamName=\"" + b + "\";" + cur.execute(search_sqi) + info1 = cur.fetchone() + # cur.execute(search_sqi) + # info1 = cur.fetchone() + if info is None: + tkinter.messagebox.showerror(title='警告', message='暂无此学生') + + elif info1 is None: + tkinter.messagebox.showerror(title='警告', message='暂无此考试') + + elif int(c) > 100 or int(c) < 0: + tkinter.messagebox.showerror(title='警告', message='成绩不符合格式') + + else: + search_sqi = "insert into studentscore(studentId,ExamName,grade) values (\"" + a + "\",\"" + b + "\"," + c + ");" + cur.execute(search_sqi) + conn.commit() + tkinter.messagebox.showinfo(title='成功', message='录入成功') + + cur.close() + + conn.close() + + def Change_Pw(self): # 修改密码触发函数 + self.window.pack_forget() + self.window = Frame(self.root) + self.window.pack() + + + Label(self.window, text='请输入旧密码: ', font=('宋体', 15)).grid(row=0, column=0, padx=5, pady=65) + self.adoldinput = Entry(self.window) + self.adoldinput.grid(row=0, column=1, padx=5, pady=5) + + + Label(self.window, text='请输入新密码: ', font=('宋体', 15)).grid(row=1, column=0, padx=5, pady=65) + self.adnewinput = Entry(self.window, show='*') + self.adnewinput.grid(row=1, column=1, padx=5, pady=5) + + + Button(self.window, text='确认', command=self.Change_Pw_Confirm, width=22, + font=('宋体', 15)).grid(row=2, column=0, padx=5, pady=65) + + def Change_Pw_Confirm(self):#修改密码确定触发函数 + a = self.adoldinput.get() + b = self.adnewinput.get() + + + conn = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8') + cur = conn.cursor() + + search_sqi = "set sql_safe_updates=0;" + cur.execute(search_sqi) + search_sqi = "select AdPassword from admini where AdID=\"" + self.id + "\";" + cur.execute(search_sqi) + info = cur.fetchone() + + if a == info[0] and b != info[0]: + search_sqi = "update admini set AdPassword =\"" + b + "\" where AdID=\"" + self.id + "\";" + cur.execute(search_sqi) + conn.commit() + tkinter.messagebox.showinfo(title='提示', message='密码修改成功!') + # elif a != info[0]: + # tkinter.messagebox.showerror(title='警告', message='旧密码输入错误') + # else: + # tkinter.messagebox.showinfo(title='提示', message='新旧密码不能一样!') + + + elif a != info[0]: + tkinter.messagebox.showerror(title='警告', message='旧密码输入错误') + + else: + tkinter.messagebox.showinfo(title='提示', message='新旧密码不能一样!') + cur.close() + conn.close() + + def Mak_A_Paper(self): # 生成一个试卷触发函数 + # self.root.attributes("-disabled", 1) + # self.test = Toplevel(self.window) + # + # self.test.geometry("530x200") + # self.test.title("试卷设置") + # Label(self.test, text='请输入考试名称: ', font=('宋体', 15)).grid(row=0, column=0, padx=10, pady=15) + # self.Examname = Entry(self.test) + # self.Examname.grid(row=0, column=3, padx=10, pady=15) + # + # Label(self.test, text='请输入考试科目: ', font=('宋体', 15)).grid(row=1, column=0, padx=10, pady=15) + # self.Coursename = Entry(self.test) + # self.Coursename.grid(row=1, column=3, padx=10, pady=15) + self.root.attributes("-disabled", 1) + self.test = Toplevel(self.window) + + self.test.geometry("530x200") + self.test.title("试卷设置") + Label(self.test, text='请输入考试名称: ', font=('宋体', 15)).grid(row=0, column=0, padx=10, pady=15) + self.Examname = Entry(self.test) + self.Examname.grid(row=0, column=3, padx=10, pady=15) + + Label(self.test, text='请输入考试科目: ', font=('宋体', 15)).grid(row=1, column=0, padx=10, pady=15) + self.Coursename = Entry(self.test) + self.Coursename.grid(row=1, column=3, padx=10, pady=15) + + Button(self.test, text='选择题目', width=10, command=self.Choose_Ques, font=('宋体', 15)).grid(row=2, column=1, + pady=15) + self.test.protocol("WM_DELETE_WINDOW", self.t_close_handler) + + def t_close_handler(self): # 顶级窗口配置函数 + self.root.attributes("-disabled", 0) + self.test.destroy() + + def Choose_Ques(self): # 管理员 进入选题界面 触发函数 + self.a = self.Examname.get() + self.b = self.Coursename.get() + conn = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8') + cur = conn.cursor() + search_sqi = "select CourseName from course where " \ + "CourseName=\"" + self.b + "\";" + cur.execute(search_sqi) + info = cur.fetchone() + if len(self.a) == 0 or info is None: + tkinter.messagebox.showerror(title='警告', message='请正确填写考试名与科目名') + + cur.close() + + conn.close() + else: + self.root.attributes("-disabled", 0) + self.test.destroy() + self.window.pack_forget() + self.window = Frame(self.root) + self.window.pack() + main_panedwindow = PanedWindow(self.window, sashrelief=RAISED, sashwidth=5, orient=VERTICAL) + + + # 当前考试题目列表区 + Ques_list_frame = Frame() + Ques_list_sub_frame = Frame(Ques_list_frame) + self.Ques_list_tree = Treeview(Ques_list_sub_frame, selectmode='browse') + self.Ques_list_tree.bind('<>', self.one_click_on_Queslist) + + + # 当前考试题目列表垂直滚动条 + Ques_list_vscrollbar = Scrollbar(Ques_list_sub_frame, orient="vertical", command=self.Ques_list_tree.yview) + Ques_list_vscrollbar.pack(side=RIGHT, fill=Y, expand=YES) + self.Ques_list_tree.configure(yscrollcommand=Ques_list_vscrollbar.set) + Ques_list_sub_frame.pack(side=TOP, fill=BOTH, expand=YES) + + + # 当前考试题目列表水平滚动条 + Ques_list_hscrollbar = Scrollbar(Ques_list_frame, orient="horizontal", command=self.Ques_list_tree.xview) + Ques_list_hscrollbar.pack(side=BOTTOM, fill=X, expand=YES) + self.Ques_list_tree.configure(xscrollcommand=Ques_list_hscrollbar.set) + + + # 当前考试题目列表区列标题 + self.Ques_list_tree["columns"] = ('选择题目编号', '选择题目内容') + Ques_list_column_width = [100, 900] + self.Ques_list_tree['show'] = 'headings' + for column_name, column_width in zip(self.Ques_list_tree["columns"], Ques_list_column_width): + self.Ques_list_tree.column(column_name, width=column_width, anchor='w') + self.Ques_list_tree.heading(column_name, text=column_name) + self.Ques_list_tree.pack(side=LEFT, fill=X, expand=YES) + + Ques_list_frame.pack(side=TOP, fill=X, padx=5, pady=5, expand=YES, anchor='n') + + + # 将数据包列表区加入到主窗体 + main_panedwindow.add(Ques_list_frame) + + AllQues_select_frame = Frame() + AllQues_select_sub_frame = Frame(AllQues_select_frame) + self.AllQues_select_tree = Treeview(AllQues_select_sub_frame, selectmode='browse') + self.AllQues_select_tree.bind('<>', self.one_click_on_AllQueslist) + + self.AllQues_select_tree.pack(side=LEFT, fill=BOTH, expand=YES) + + + # 考试选择区垂直滚动条 + AllQues_select_vscrollbar = Scrollbar(AllQues_select_sub_frame, orient="vertical", + command=self.AllQues_select_tree.yview) + AllQues_select_vscrollbar.pack(side=RIGHT, fill=Y) + self.AllQues_select_tree.configure(yscrollcommand=AllQues_select_vscrollbar.set) + # AllQues_select_vscrollbar.pack(side=RIGHT, fill=Y) + # self.AllQues_select_tree.configure(yscrollcommand=AllQues_select_vscrollbar.set) + AllQues_select_sub_frame.pack(side=TOP, fill=X, expand=YES) + + + # 考试选择区水平滚动条 + AllQues_select_hsc = Scrollbar(AllQues_select_frame, orient="horizontal", + command=self.AllQues_select_tree.xview) + AllQues_select_hsc.pack(side=BOTTOM, fill=X) + + self.AllQues_select_tree.configure(xscrollcommand=AllQues_select_hsc.set) + + AllQues_select_frame.pack(side=LEFT, fill=X, padx=5, pady=5, expand=YES) + # 载入列标题 + self.AllQues_select_tree["columns"] = ("题目编号", "题目内容") + AllQues_select_column_width = [100, 900] + self.AllQues_select_tree['show'] = 'headings' + # for column_name, column_width in zip(self.AllQues_select_tree["columns"], AllQues_select_column_width): + + # self.AllQues_select_tree.column(column_name, width=column_width, anchor='w') + + # self.AllQues_select_tree.heading(column_name, text=column_name) + + # self.AllQues_select_tree.pack(side=LEFT, fill=X, expand=YES) + + # AllQues_select_frame.pack(side=TOP, fill=X, padx=5, pady=5, expand=YES, anchor='n') + for column_name, column_width in zip(self.AllQues_select_tree["columns"], AllQues_select_column_width): + self.AllQues_select_tree.column(column_name, width=column_width, anchor='w') + self.AllQues_select_tree.heading(column_name, text=column_name) + self.AllQues_select_tree.pack(side=LEFT, fill=X, expand=YES) + + AllQues_select_frame.pack(side=TOP, fill=X, padx=5, pady=5, expand=YES, anchor='n') + + + # 将考试列表区加入到主窗体 + main_panedwindow.add(AllQues_select_frame) + main_panedwindow.pack(fill=BOTH, expand=1) + + search_sqi = "select QuesId,QuesContent from questions,course where " \ + "CourseName=\"" + self.b + "\" and questions.CourseID = course.CourseId;" + cur.execute(search_sqi) + i = 1 + + for row in cur: + self.AllQues_select_tree.insert("", "end", str(i), values=row) + i = i + 1 + self.AllQues_array.append(row) + self.AllQues_select_tree.update_idletasks() + cur.close() + conn.close() + + def one_click_on_Queslist(self, event): # 单击 考试题目 触发函数 + ask = messagebox.askyesno(title="确认", message="您确定删除此题吗?") + if ask == 1: + self.Ques_array.remove(self.Ques_array[int(self.Ques_list_tree.selection()[0])-1]) + + self.Ques_list_tree.delete(*self.Ques_list_tree.get_children()) + + self.i = 1 + # self.Ques_array.remove(self.Ques_array[int(self.Ques_list_tree.selection()[0]) - 1]) + # self.Ques_list_tree.delete(*self.Ques_list_tree.get_children()) + # self.i = 1 + for row in self.Ques_array: + self.Ques_list_tree.insert("", 'end', str(self.i), text='', values=row) + self.i += 1 + + self.Ques_list_tree.update_idletasks() + + tkinter.messagebox.showinfo(title='提示', message='删除成功' + '') + self.write() + + def one_click_on_AllQueslist(self, event): # 单击 题库 触发函数 + ask = messagebox.askyesno(title="确认", message="您确定添加此题吗?") + if ask == 1: + self.Ques_array.append(self.AllQues_array[int(self.AllQues_select_tree.selection()[0])-1]) + self.Ques_list_tree.delete(*self.Ques_list_tree.get_children()) + self.i = 1 + for row in self.Ques_array: + self.Ques_list_tree.insert("", 'end', str(self.i), text='', values=row) + self.i += 1 + self.Ques_list_tree.update_idletasks() + print(self.Ques_array) + tkinter.messagebox.showinfo(title='提示', message='添加成功') + self.write() + # def SomeMessage(self): + # def justatest(): + # # justatest 测试后删除 + # course_list_tree.insert("", "end", 1, values=('Sue', 'I need your help, my dearest teacher~ ')) + # course_list_tree.insert("", "end", 2, values=('Bob', 'Just fake news ')) + # course_list_tree.insert("", "end", 3, values=('Mark', 'Can U speak Chinese?')) + # course_list_tree.insert("", "end", 4, values=('John', 'I got it!')) + # course_list_tree.insert("", "end", 5, values=('李志华', '老师我肚子痛明天不去上课了,抱歉')) + # course_list_tree.insert("", "end", 6, values=('张庆源', '老师作业打回一下吧!')) + # course_list_tree.insert("", "end", 7, values=('禾木艾', ' 发错了')) + # course_list_tree.insert("", "end", 8, values=('测试', '进入测试')) + # course_list_tree.insert("", "end", 10, values=('测试2', '进入测试进入测试进入测试')) + # course_list_tree.update_idletasks() + def write(self): + if self.i == 11: + ask = messagebox.askyesno(title="确认", message="已添加10道题,是否生成试卷?") + if ask == 1: + conn = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8') + cur = conn.cursor() + search_sqi = "select * from examnation order by ExamID DESC LIMIT 1;" + cur.execute(search_sqi) + info = cur.fetchone() + no = str(int(info[0])+1) + search_sqi = "select CourseID from course where CourseName=\"" + self.b + "\";" + cur.execute(search_sqi) + info = cur.fetchone() + search_sqi = "insert into examnation values " \ + "(\"" + no + "\"," \ + "\"" + self.a + "\",\"" + self.id + "\",\"" + info[0] + "\",\"" + self.Ques_array[0][0] + "\",\"" + self.Ques_array[1][0] + "\",\"" + self.Ques_array[2][0] + "\",\"" + self.Ques_array[3][0] + "\",\"" + self.Ques_array[4][0] + "\",\"" + self.Ques_array[5][0] + "\",\"" + self.Ques_array[6][0] + "\",\"" + self.Ques_array[7][0] + "\",\"" + self.Ques_array[8][0] + "\",\"" + self.Ques_array[9][0] + "\");" + cur.execute(search_sqi) + conn.commit() + + tkinter.messagebox.showinfo(title='提示', message='成功生成试卷') + cur.close() + conn.close() + elif self.i > 11: + tkinter.messagebox.showinfo(title='提示', message='添加的题目数量过多') + + def SomeMessage(self): + def justatest(): + # justatest 测试后删除 + course_list_tree.insert("", "end", 1, values=('大咸鱼', 'I need your help, my dearest teacher')) + + course_list_tree.insert("", "end", 2, values=('大咸鱼', 'Just fake news ')) + course_list_tree.insert("", "end", 3, values=('翠花', 'Can U speak Chinese?')) + course_list_tree.insert("", "end", 4, values=('张大宝', 'I got it!')) + course_list_tree.insert("", "end", 5, values=('张大宝', '老师我肚子痛明天不去上课了,抱歉')) + + course_list_tree.insert("", "end", 6, values=('张大宝', '老师作业打回一下吧!')) + course_list_tree.insert("", "end", 7, values=('翠花', ' 发错了')) + course_list_tree.insert("", "end", 8, values=('翠花', '进入测试')) + course_list_tree.insert("", "end", 10, values=('大咸鱼', '进入测试进入测试进入测试')) + course_list_tree.insert("", "end", 11, values=('翠花', '1')) + course_list_tree.update_idletasks() + + # 点击 信息列表 时的单击响应函数 + def on_click_message_list_tree(event): + print(course_list_tree.get_children()) + print(course_list_tree.selection()) + ask = messagebox.askyesno(title="采纳?", message="此条留言您是否采纳?") + + if ask == 1: + messagebox.showinfo(title="提示", message="您已采纳该留言!") + course_list_tree.delete(course_list_tree.selection()[0]) + course_list_tree.update_idletasks() + + else: + ask1 = messagebox.askyesno(title="提示", message="您确定不采纳吗?") + if ask1 == 1: + messagebox.showinfo(title="提示", message="您选择了不采纳,已反馈给学生端!") + course_list_tree.delete(course_list_tree.selection()[0]) + course_list_tree.update_idletasks() + self.window.pack_forget() + self.window = Frame(self.root) + self.window.pack() + + main_panedwindow = PanedWindow(self.window, sashrelief=RAISED, sashwidth=5, orient=VERTICAL) + + + # 课程列表区 + course_list_frame = Frame() + course_list_sub_frame = Frame(course_list_frame) + course_list_tree = Treeview(course_list_sub_frame, selectmode='browse') + course_list_tree.bind('<>', on_click_message_list_tree) + + course_list_vscrollbar = Scrollbar(course_list_sub_frame, orient="vertical", command=course_list_tree.yview) + course_list_vscrollbar.pack(side=RIGHT, fill=Y, expand=YES) + course_list_tree.configure(yscrollcommand=course_list_vscrollbar.set) + course_list_sub_frame.pack(side=TOP, fill=BOTH, expand=YES) + + course_list_hscrollbar = Scrollbar(course_list_frame, orient="horizontal", command=course_list_tree.xview) + course_list_hscrollbar.pack(side=BOTTOM, fill=X, expand=YES) + course_list_tree.configure(xscrollcommand=course_list_hscrollbar.set) + + course_list_tree["columns"] = ("StudentName", "Message") + course_list_column_width = [500, 500] + course_list_tree['show'] = 'headings' + # 载入列标题 + for column_name, column_width in zip(course_list_tree["columns"], course_list_column_width): + course_list_tree.column(column_name, width=column_width, anchor='w') + course_list_tree.heading(column_name, text=column_name) + course_list_tree.pack(side=LEFT, fill=X, expand=YES) + course_list_frame.pack(side=TOP, fill=X, padx=5, pady=5, expand=YES, anchor='n') + # 将数据包列表区加入到主窗体 + main_panedwindow.add(course_list_frame) + main_panedwindow.pack() + # main_panedwindow.pack(fill=BOTH, expand=1) + justatest() # 测试 + # course_list_frame = Frame() + # course_list_sub_frame = Frame(course_list_frame) + # course_list_tree = Treeview(course_list_sub_frame, selectmode='browse') + # course_list_tree.bind('<>', on_click_message_list_tree) + + + # course_list_vscrollbar = Scrollbar(course_list_sub_frame, orient="vertical", command=course_list_tree.yview) + # course_list_vscrollbar.pack(side=RIGHT, fill=Y, expand=YES) + # course_list_tree.configure(yscrollcommand=course_list_vscrollbar.set) + # course_list_sub_frame.pack(side=TOP, fill=BOTH, expand=YES) + # + # course_list_hscrollbar = Scrollbar(course_list_frame, orient="horizontal", command=course_list_tree.xview) + # course_list_hscrollbar.pack(side=BOTTOM, fill=X, expand=YES) + # course_list_tree.configure(xscrollcommand=course_list_hscrollbar.set) + + def Markitright(self): + window = Tk() + window.title("Mark") + + canvas = Canvas(window, bg="SandyBrown", width=480, height=480) + canvas.grid(row=0, column=0, rowspan=10) + + + for i in range(15): + canvas.create_line(30, (30 * i + 30), 450, (30 * i + 30)) + canvas.create_line((30 * i + 30), 30, (30 * i + 30), 450) + + # + point_x = [3, 3, 11, 11, 7] + point_y = [3, 11, 3, 11, 7] + for i in range(5): + canvas.create_oval(30 * point_x[i] + 27, 30 * point_y[i] + 27, + 30 * point_x[i] + 33, 30 * point_y[i] + 33, fill="black") + + + r = 10 + click_x = 0 + click_y = 0 + piece_color = "black" + person_flag = 1 + a_flag = 1 # + mouse_black = [] + mouse_white = [] + mouse = [] + totala = 0 + totalb = 0 + ret = 1 + + + def mouseBack(event): + global click_x, click_y + click_x = event.x + click_y = event.y + mouseJudge() + + + canvas.bind("", mouseBack) + + + def mouseJudge(): + global click_x, click_y, person_flag, mouse + mouse = mouse_black + mouse_white + i = 0 + j = 0 + while click_x > (30 + 15 * i): + i += 1 + while click_y > (30 + 15 * j): + j += 1 + if ((i % 2) == 1 and (j % 2) == 1): + click_x = 30 + 15 * (i - 1) + click_y = 30 + 15 * (j - 1) + if ((i % 2) == 1 and (j % 2) == 0): + click_x = 30 + 15 * (i - 1) + click_y = 30 + 15 * j + if ((i % 2) == 0 and (j % 2) == 1): + click_x = 30 + 15 * i + click_y = 30 + 15 * (j - 1) + if ((i % 2) == 0 and (j % 2) == 0): + click_x = 30 + 15 * i + click_y = 30 + 15 * j + if person_flag == 1: + putPiece("black") + elif person_flag == -1: + putPiece("white") + + # r = 10 + # click_x = 0 + # click_y = 0 + # piece_color = "black" + # person_flag = 1 + # a_flag = 1 # + # mouse_black = [] + # mouse_white = [] + # mouse = [] + # totala = 0 + # totalb = 0 + # ret = 1 + def putPiece(piece_color): + global mouse_black, mouse_white, person_flag, mouse, ret + ret = 1 + if (click_x >= 30) and (click_x <= 450) and (click_y >= 30) and (click_y <= 450): + if (click_x, click_y) not in mouse: + if a_flag == 0: + canvas.create_oval(click_x - r, click_y - r, + click_x + r, click_y + r, + fill=piece_color, tags=("piece")) + person_flag *= -1 + if piece_color == "white": + Show(mouse) + mouse_white.append((click_x, click_y)) + Judge1(mouse_white) + Tips(mouse) + elif piece_color == "black": + Show(mouse) + mouse_black.append((click_x, click_y)) + Judge1(mouse_black) + Tips(mouse) + else: + return 0 + + + def pieceCount(mouse, pieces_count, p, q): + global piece_count + if person_flag == -1: + for i in range(1, 5): + (x, y) = (click_x + p * 30 * i, click_y + q * 30 * i) + if (x, y) in mouse_black: + piece_count += 1 + else: + break + return piece_count + if person_flag == 1: + for i in range(1, 5): + (x, y) = (click_x + p * 30 * i, click_y + q * 30 * i) + if (x, y) in mouse_white: + piece_count += 1 + else: + break + return piece_count + + + def Judge1(mouse): + global piece_count, piece_color + piece_count = 0 + piece_count = pieceCount(mouse, piece_count, -1, 0) + piece_count = pieceCount(mouse, piece_count, 1, 0) + + if piece_count == 3: + return 1 + elif piece_count > 3: + return 5 + else: + piece_count = 0 + piece_count = pieceCount(mouse, piece_count, 0, -1) # 判断 + piece_count = pieceCount(mouse, piece_count, 0, 1) # + if piece_count == 3: + return 1 + elif piece_count > 3: + return 5 + else: + piece_count = 0 + piece_count = pieceCount(mouse, piece_count, -1, -1) + piece_count = pieceCount(mouse, piece_count, 1, 1) + if piece_count == 3: + return 1 + elif piece_count > 3: + return 5 + else: + piece_count = 0 + piece_count = pieceCount(mouse, piece_count, 1, -1) # + piece_count = pieceCount(mouse, piece_count, -1, 1) # + if piece_count == 3: + return 1 + elif piece_count > 3: + return 5 + else: + return 0 + + + def Show(mouse): + var1 = StringVar() + if person_flag == 1: + piece_canvas = Canvas(window, width=200, height=50) + piece_canvas.grid(row=0, column=1) + piece_canvas.create_oval(100 - r, 30 - r, + 100 + r, 30 + r, + fill='black') + var1.set("00") + label = Label(window, textvariable=var1, font=("宋体", 16)) + label.grid(row=1, column=1) + if person_flag == -1: + piece_canvas = Canvas(window, width=200, height=50) + piece_canvas.grid(row=0, column=1) + piece_canvas.create_oval(100 - r, 30 - r, + 100 + r, 30 + r, + fill='white') + var1.set("09") + label = Label(window, textvariable=var1, font=("宋体", 16)) + label.grid(row=1, column=1) + def Showddw(mouse): + var1 = StringVar() + if person_flag == 1: + piece_canvas = Canvas(window, width=200, height=50) + piece_canvas.grid(row=0, column=1) + piece_canvas.create_oval(100 - r, 30 - r, + 100 + r, 30 + r, + fill='black') + var1.set("00") + label = Label(window, textvariable=var1, font=("宋体", 16)) + label.grid(row=1, column=1) + if person_flag == -1: + piece_canvas = Canvas(window, width=200, height=50) + piece_canvas.grid(row=0, column=1) + piece_canvas.create_oval(100 - r, 30 - r, + 100 + r, 30 + r, + fill='white') + var1.set("09") + label = Label(window, textvariable=var1, font=("宋体", 16)) + label.grid(row=1, column=1) + + def Tips(mouse): + var2 = StringVar() + global a_flag, totala, totalb + if len(mouse) == 224: # 如果棋盘铺满 + if totala > totalb: + var2.set("黑9" % (totala, totalb)) + label = Label(window, textvariable=var2, font=("宋体", 16)) + label.grid(row=2, column=1) + a_flag = 1 + return a_flag + elif totala < totalb: + var2.set("黑8" % (totala, totalb)) + label = Label(window, textvariable=var2, font=("宋体", 16)) + label.grid(row=2, column=1) + a_flag = 1 + return a_flag + else: + var2.set("黑6" % (totala, totalb)) + label = Label(window, textvariable=var2, font=("宋体", 16)) + label.grid(row=2, column=1) + a_flag = 1 + return a_flag + if person_flag == -1: + totala += Judge1(mouse) + var2.set("黑5" % (totala, totalb)) + label = Label(window, textvariable=var2, font=("宋体", 16)) + label.grid(row=2, column=1) + # a_flag = 1 + return a_flag + if person_flag == 1: + totalb += Judge1(mouse) + var2.set("黑4" % (totala, totalb)) + label = Label(window, textvariable=var2, font=("宋体", 16)) + label.grid(row=2, column=1) + # a_flag = 1 + return a_flag + + + def c_reset(): + var3 = StringVar() + global a_flag, mouse_black, mouse_white, mouse, totala, totalb + canvas.delete("piece") + mouse_black = [] + mouse_white = [] + mouse = [] + a_flag = 0 + totala, totalb = 0, 0 + var3.set(" ") + label = Label(window, textvariable=var3, font=("宋体", 16)) + label.grid(row=2, column=1) + + # mouse = [] + # a_flag = 0 + # totala, totalb = 0, 0 + # var3.set(" ") + # label = Label(window, textvariable=var3, font=("宋体", 16)) + # label.grid(row=2, column=1) + + def click_return(): + global mouse_black, mouse_white, mouse, person_flag, totala, totalb, ret + if ret == 0: + return + canvas.delete("piece") + ret = 0 + var2 = StringVar() + if person_flag == -1: + mouse_black.pop() + mouse = mouse_black + mouse_white + totala -= Judge1(mouse) + var2.set("6" % (totala, totalb)) + label = Label(window, textvariable=var2, font=("宋体", 16)) + label.grid(row=2, column=1) + + for i in range(len(mouse_black)): + canvas.create_oval(mouse_black[i][0] - r, mouse_black[i][1] - r + , mouse_black[i][0] + r, mouse_black[i][1] + r, fill="black", tags="piece") + for i in range(len(mouse_white)): + canvas.create_oval(mouse_white[i][0] - r, mouse_white[i][1] - r + , mouse_white[i][0] + r, mouse_white[i][1] + r, fill="white", tags="piece") + + if person_flag == 1: + for i in range(len(mouse_black)): + canvas.create_oval(mouse_black[i][0] - r, mouse_black[i][1] - r + , mouse_black[i][0] + r, mouse_black[i][1] + r, fill="black", tags="piece") + mouse_white.pop() + mouse = mouse_black + mouse_white + totalb -= Judge1(mouse) + var2.set("5=" % (totala, totalb)) + label = Label(window, textvariable=var2, font=("宋体", 16)) + label.grid(row=2, column=1) + + for i in range(len(mouse_white)): + canvas.create_oval(mouse_white[i][0] - r, mouse_white[i][1] - r + , mouse_white[i][0] + r, mouse_white[i][1] + r, fill="white", tags="piece") + person_flag *= -1 + Show(mouse) + + button1 = Button(window, text="6", font=('黑体', 10), fg='blue', width=10, height=2, command=c_reset) + button1.grid(row=4, column=1) + button2 = Button(window, text="", font=('黑体', 10), fg='red', width=10, height=2, command=click_return) + button2.grid(row=6, column=1) + var = StringVar() + piece_canvas = Canvas(window, width=200, height=50) + piece_canvas.grid(row=0, column=1) + piece_canvas.create_oval(100 - r, 30 - r, 100 + r, 30 + r, fill='black') + var.set("56") + label = Label(window, textvariable=var, font=("宋体", 16)) + label.grid(row=1, column=1) + window.mainloop() + # + # course_list_tree["columns"] = ("StudentName", "Message") + # course_list_column_width = [500, 500] + # course_list_tree['show'] = 'headings' + # # 载入列标题 + # for column_name, column_width in zip(course_list_tree["columns"], course_list_column_width): + # course_list_tree.column(column_name, width=column_width, anchor='w') + # course_list_tree.heading(column_name, text=column_name) + # course_list_tree.pack(side=LEFT, fill=X, expand=YES) + # course_list_frame.pack(side=TOP, fill=X, padx=5, pady=5, expand=YES, anchor='n') + +if __name__ == '__main__': + root = Tk() + AdSc(root, '12034012') + root.mainloop() diff --git a/src/LoginScreen.py b/src/LoginScreen.py new file mode 100644 index 0000000..455ed86 --- /dev/null +++ b/src/LoginScreen.py @@ -0,0 +1,101 @@ +import tkinter + +from tkinter import * +import tkinter.messagebox +from exam.AdScreen import AdSc +from StuScreen import StuSc + +import pymysql + + +class LoginScreen: + def __init__(self, master): + self.root = master + self.root.title('在线考试系统') + + self.root.geometry('800x260') + + self.window = Frame(self.root) + self.window.pack() + # Label(self.window) + # Label(self.window, text= + + + # '在线考试系统', font=('宋体', 25)). + # grid(row=0, column=1, padx=15, pady=15) + # Label(self.window, text='请输入账号: ', font=('宋体', 15)).grid(row=1, column=0, padx=15, pady=15) + Label(self.window) + Label(self.window, text='在线考试系统', font=('宋体', 25)).grid(row=0, column=1, padx=15, pady=15) + + Label(self.window, text='请输入账号: ', font=('宋体', 15)).grid(row=1, column=0, padx=15, pady=15) + + self.UserAccountInput = Entry(self.window) + + self.UserAccountInput.grid(row=1, column=3, padx=15, pady=15) + + Label(self.window, text='请输入密码: ', font=('宋体', 15)).grid(row=2, column=0, padx=15, pady=15) + + self.UserPasswordInput = Entry(self.window, show='*') + + self.UserPasswordInput.grid(row=2, column=3, padx=15, pady=15) + + Button(self.window, text='登陆', width=20, command=self.login,font=('宋体', 15)).grid(row=3, column=1, padx=15, pady=15) + + def login(self): + a = self.UserAccountInput.get() + + b = self.UserPasswordInput.get() + + conn = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8') + + cur = conn.cursor() + if a[0] == '1': + + search_sqi = "select AdPassword from admini where AdID=\""+a+"\";" + cur.execute(search_sqi) + info = cur.fetchone() + if info is None: + + tkinter.messagebox.showerror(title='警告!', message='暂无该用户名!') + + elif b == info[0]: + + self.window.destroy() + AdSc(self.root, a) + else: + tkinter.messagebox.showerror(title='警告!', message='用户名或密码错误!') + + else: + search_sqi = "select studentPassword from student where studentId=\""+a+"\";" + cur.execute(search_sqi) + info = cur.fetchone() + + if info is None: + tkinter.messagebox.showerror(title='警告!', message='暂无该用户名!') + elif b == info[0]: + + self.window.destroy() + + StuSc(self.root, a) + # else: + # tkinter.messagebox.showerror(title='警告!', message='用户名或密码错误!') + + # if info is None: + + # tkinter.messagebox.showerror(title='警告!', message='暂无该用户名!') + # elif b == info[0]: + + # self.window.destroy() + # StuSc(self.root, a) + # else: + # tkinter.messagebox.showerror(title='警告!', message='用户名或密码错误!') + cur.close() + + conn.close() + + +if __name__ == '__main__': + window = Tk() + LoginScreen(window) + window.mainloop() + diff --git a/src/StuScreen.py b/src/StuScreen.py new file mode 100644 index 0000000..e0380aa --- /dev/null +++ b/src/StuScreen.py @@ -0,0 +1,597 @@ +import tkinter +from tkinter import * +from tkinter import messagebox +from tkinter.messagebox import * +from tkinter.ttk import Treeview +import random +import pymysql +import time + + +class StuSc: + def __init__(self, master, no): + + self.window1 = None + self.course_array = [] + + self.exam_array = [] + self.id = no + + self.flag = 0 + self.que_no = 1 + self.root = master + self.root.geometry('1100x500') + self.root.title('考生主页') + + self.window = Frame(self.root) + self.window.pack() + self.main_menu = Menu(self.window) + + self.main_menu.add_cascade(label="考试", command=self.show_course) + + self.main_menu.add_command(label="查询成绩", command=self.sel_score) + + self.main_menu.add_command(label="修改密码", command=self.chan_pw) + + self.main_menu.add_command(label="发送留言", command=self.SendM) + self.UserOldInput = Entry(self.window) + + self.UserNewInput = Entry(self.window, show='*') + + self.root.config(menu=self.main_menu) + + def show_course(self): + if self.flag == 1: + messagebox.showerror(title='警告', message='请专注于当前考试') + + else: + self.window.pack_forget() + self.window = Frame(self.root) + self.window.pack() + + + # 点击 考试列表 时单击响应 + def on_click_exam_list_tree(event): + if self.flag == 1: + messagebox.showerror(title='警告', message='请专注于当前考试') + + else: + selected_item = event.widget.selection() + exam_id = self.exam_array[int(selected_item[0]) - 1][0] + ask = askyesno(title="考试提醒", message="是否确定进入?", ) + + if ask: + self.flag = 1 + timestamp = int(time.time()) + time_local = time.localtime(timestamp) + + timetable = time.strftime("%Y-%m-%d %H:%M:%S", time_local) + self.Exam(exam_id, timetable) + + + # 点击 课程列表 时的单击响应函数 + + def on_click_course_list_tree(event): + + if self.flag == 1: + messagebox.showerror(title='警告', message='请专注于当前考试') + else: + + + selected_item = event.widget.selection() # event.widget获取Treeview对象,调用selection获取选择对象名称 + # 清空exam_select_tree上现有的内容 + # 清空exam_select_tree上现有的内容 + exam_select_tree.delete(*exam_select_tree.get_children()) + course_name = self.course_array[int(selected_item[0])-1][1] + ad_id = self.course_array[int(selected_item[0])-1][2] + + + conn1 = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8') + cur1 = conn1.cursor() + search_sqi1 = "select ExamID,ExamName from examnation,Course where CourseName=\""+course_name + \ + "\" and examnation.AdID=\"" + ad_id + "\"and examnation.CourseID=Course.CourseID;" + cur1.execute(search_sqi1) + j = 1 + + for row1 in cur1: + exam_select_tree.insert("", 'end', str(j), text='', values=row1) + j = j+1 + self.exam_array.append(row1) + exam_select_tree.update_idletasks() + cur1.close() + conn1.close() + + main_panedwindow = PanedWindow(self.window, sashrelief=RAISED, sashwidth=5, orient=VERTICAL) + + # 课程列表区 + course_list_frame = Frame() + course_list_sub_frame = Frame(course_list_frame) + course_list_tree = Treeview(course_list_sub_frame, selectmode='browse') + course_list_tree.bind('<>', on_click_course_list_tree) + + # 课程列表垂直滚动条 + course_list_vsc = Scrollbar(course_list_sub_frame, orient="vertical", command=course_list_tree.yview) + course_list_vsc.pack(side=RIGHT, fill=Y, expand=YES) + course_list_tree.configure(yscrollcommand=course_list_vsc.set) + course_list_sub_frame.pack(side=TOP, fill=BOTH, expand=YES) + + # 课程列表水平滚动条 + course_list_hsc = Scrollbar(course_list_frame, orient="horizontal", command=course_list_tree.xview) + course_list_hsc.pack(side=BOTTOM, fill=X, expand=YES) + course_list_tree.configure(xscrollcommand=course_list_hsc.set) + + # 课程列表区列标题 + course_list_tree["columns"] = ("CourseID", "CourseName", "AdID") + course_list_column_width = [333, 333, 333] + + course_list_tree['show'] = 'headings' + # 载入列标题 + + for column_name, column_width in zip(course_list_tree["columns"], course_list_column_width): + course_list_tree.column(column_name, width=column_width, anchor='w') + course_list_tree.heading(column_name, text=column_name) + + course_list_tree.pack(side=LEFT, fill=X, expand=YES) + course_list_frame.pack(side=TOP, fill=X, padx=5, pady=5, expand=YES, anchor='n') + + # 将数据包列表区加入到主窗体 + main_panedwindow.add(course_list_frame) + conn = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8') + cur = conn.cursor() + search_sqi = "select * from Course;" + cur.execute(search_sqi + ) + i = 1 + + for row in cur: + course_list_tree.insert("", "end", str(i), values=row) + i = i + 1 + self.course_array.append(row) + course_list_tree.update_idletasks() + cur.close() + conn.close() + + # 考试选择区 + exam_select_frame = Frame() + exam_select_sub_frame = Frame(exam_select_frame) + exam_select_tree = Treeview(exam_select_sub_frame, selectmode='browse') + exam_select_tree.bind('<>', on_click_exam_list_tree) + exam_select_tree.pack(side=LEFT, fill=BOTH, expand=YES) + + # 考试选择区垂直滚动条 + exam_select_vsc = Scrollbar(exam_select_sub_frame, orient="vertical", command=exam_select_tree.yview) + exam_select_vsc.pack(side=RIGHT, fill=Y) + exam_select_tree.configure(yscrollcommand=exam_select_vsc.set) + exam_select_sub_frame.pack(side=TOP, fill=X, expand=YES) + + # 考试选择区水平滚动条 + exam_select_hsc = Scrollbar(exam_select_frame, orient="horizontal", command=exam_select_tree.xview) + exam_select_hsc.pack(side=BOTTOM, fill=X) + exam_select_tree.configure(xscrollcommand=exam_select_hsc.set) + exam_select_frame.pack(side=LEFT, fill=X, padx=5, pady=5, expand=YES) + + # 载入列标题 + exam_select_tree["columns"] = ("ExamID", "ExamName") + exam_select_column_width = [500, 500] + exam_select_tree['show'] = 'headings' + for column_name, column_width in zip(exam_select_tree["columns"], exam_select_column_width): + exam_select_tree.column(column_name, width=column_width, anchor='w') + exam_select_tree.heading(column_name, text=column_name) + exam_select_tree.pack(side=LEFT, fill=X, expand=YES) + exam_select_frame.pack(side=TOP, fill=X, padx=5, pady=5, expand=YES, anchor='n') + + # 将考试列表区加入到主窗体 + main_panedwindow.add(exam_select_frame) + main_panedwindow.pack(fill=BOTH, expand=1) + + def sel_score(self): + if self.flag == 1: + messagebox.showerror(title='警告', message='请专注于当前考试') + else: + self.window.pack_forget() + self.window = Frame(self.root) + self.window.pack() + main_panedwindow = PanedWindow(self.window, sashrelief=RAISED, sashwidth=5, orient=VERTICAL) + + # 课程列表区 + score_list_frame = Frame() + score_list_sub_frame = Frame(score_list_frame) + score_list_tree = Treeview(score_list_sub_frame, selectmode='browse') + + # # 课程列表垂直滚动条 + # score_list_vsc = Scrollbar(score_list_sub_frame, orient="vertical", command=score_list_tree.yview) + # score_list_vsc.pack(side=RIGHT, fill=Y, expand=YES) + # score_list_tree.configure(yscrollcommand=score_list_vsc.set) + # score_list_sub_frame.pack(side=TOP, fill=BOTH, expand=YES) + # + # # 课程列表水平滚动条 + # score_list_hsc = Scrollbar(score_list_frame, orient="horizontal", command=score_list_tree.xview) + # score_list_hsc.pack(side=BOTTOM, fill=X, expand=YES) + # score_list_tree.configure(xscrollcommand=score_list_hsc.set) + + # 课程列表垂直滚动条 + score_list_vsc = Scrollbar(score_list_sub_frame, orient="vertical", command=score_list_tree.yview) + score_list_vsc.pack(side=RIGHT, fill=Y, expand=YES) + score_list_tree.configure(yscrollcommand=score_list_vsc.set) + score_list_sub_frame.pack(side=TOP, fill=BOTH, expand=YES) + + # 课程列表水平滚动条 + score_list_hsc = Scrollbar(score_list_frame, orient="horizontal", command=score_list_tree.xview) + score_list_hsc.pack(side=BOTTOM, fill=X, expand=YES) + score_list_tree.configure(xscrollcommand=score_list_hsc.set) + + # 课程列表区列标题 + score_list_tree["columns"] = ('ExamName', 'Grade', 'beginTime', 'endTime') + score_list_column_width = [250, 250, 250, 250] + score_list_tree['show'] = 'headings' + + # 载入列标题 + for column_name, column_width in zip(score_list_tree["columns"], score_list_column_width): + score_list_tree.column(column_name, width=column_width, anchor='w') + score_list_tree.heading(column_name, text=column_name) + score_list_tree.pack(side=LEFT, fill=X, expand=YES) + score_list_frame.pack(side=TOP, fill=X, padx=5, pady=5, expand=YES, anchor='n') + + # 将数据包列表区加入到主窗体 + main_panedwindow.add(score_list_frame) + main_panedwindow.pack(fill=BOTH, expand=1) + conn = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8') + cur = conn.cursor() + search_sqi = "select ExamName,grade,beginTime,endTime from studentscore where " \ + "studentId=\"" + self.id + "\";" + cur.execute(search_sqi) + i = 1 + for row in cur: + score_list_tree.insert("", "end", str(i), values=row) + i = i + 1 + score_list_tree.update_idletasks() + cur.close() + conn.close() + + def chan_pw(self): + if self.flag == 1: + messagebox.showerror(title='警告', message='请专注于当前考试') + else: + self.window.pack_forget() + self.window = Frame(self.root) + self.window.pack() + Label(self.window, text='请输入旧密码: ', font=('宋体', 15)).grid(row=0, column=0, padx=70, pady=70) + self.UserOldInput = Entry(self.window) + self.UserOldInput.grid(row=0, column=1, padx=75, pady=75) + Label(self.window, text='请输入新密码: ', font=('宋体', 15)).grid(row=1, column=0, padx=70, pady=70) + self.UserNewInput = Entry(self.window, show='*') + self.UserNewInput.grid(row=1, column=1, padx=75, pady=75) + Button(self.window, text='确认', width=10, command=self.confirm, + font=('宋体', 15)).grid(row=2, column=0, padx=70, pady=70) + + def confirm(self): + a = self.UserOldInput.get() + b = self.UserNewInput.get() + + conn = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8') + cur = conn.cursor() + search_sqi = "set sql_safe_updates=0;" + cur.execute(search_sqi) + search_sqi = "select studentPassword from student where studentId=\"" + self.id + "\";" + cur.execute(search_sqi) + info = cur.fetchone() + if a == info[0] and b != info[0]: + search_sqi = "update student set studentPassword =\"" + b + "\" where studentId=\"" + self.id + "\";" + cur.execute(search_sqi) + conn.commit() + tkinter.messagebox.showinfo(title='提示', message='密码修改成功!') + elif a != info[0]: + tkinter.messagebox.showerror(title='警告', message='旧密码输入错误') + else: + tkinter.messagebox.showinfo(title='提示', message='新旧密码不能一样!') + cur.close() + conn.close() + + def Exam(self, exam_id, begin_time): + def Ques_ABCD(num): + + self.que_no = num + + no = "第" + str(self.que_no) + "题选项" + ts["text"] = no + if user_answer[num - 1] == 'A': + bta["bg"] = mychoicecolor + btb["bg"] = choicecolor + btc["bg"] = choicecolor + btd["bg"] = choicecolor + elif user_answer[num - 1] == 'B': + bta["bg"] = choicecolor + btb["bg"] = mychoicecolor + btc["bg"] = choicecolor + btd["bg"] = choicecolor + elif user_answer[num - 1] == 'C': + bta["bg"] = choicecolor + btb["bg"] = choicecolor + btc["bg"] = mychoicecolor + btd["bg"] = choicecolor + elif user_answer[num - 1] == 'D': + bta["bg"] = choicecolor + btb["bg"] = choicecolor + btc["bg"] = choicecolor + btd["bg"] = mychoicecolor + else: + bta["bg"] = choicecolor + btb["bg"] = choicecolor + btc["bg"] = choicecolor + btd["bg"] = choicecolor + + def Choice_change(y): + if y == 'A': + bta["bg"] = mychoicecolor + btb["bg"] = choicecolor + btc["bg"] = choicecolor + btd["bg"] = choicecolor + elif y == 'B': + bta["bg"] = choicecolor + btb["bg"] = mychoicecolor + btc["bg"] = choicecolor + btd["bg"] = choicecolor + elif y == 'C': + bta["bg"] = choicecolor + btb["bg"] = choicecolor + btc["bg"] = mychoicecolor + btd["bg"] = choicecolor + else: + bta["bg"] = choicecolor + btb["bg"] = choicecolor + btc["bg"] = choicecolor + btd["bg"] = mychoicecolor + user_answer[self.que_no - 1] = y + if self.que_no == 1: + button1["bg"] = mychoicecolor + elif self.que_no == 2: + button2["bg"] = mychoicecolor + elif self.que_no == 3: + button3["bg"] = mychoicecolor + elif self.que_no == 4: + button4["bg"] = mychoicecolor + elif self.que_no == 5: + button5["bg"] = mychoicecolor + elif self.que_no == 6: + button6["bg"] = mychoicecolor + elif self.que_no == 7: + button7["bg"] = mychoicecolor + elif self.que_no == 8: + button8["bg"] = mychoicecolor + elif self.que_no == 9: + button9["bg"] = mychoicecolor + else: + button10["bg"] = mychoicecolor + + def Paperover_Confirm(): + for op in user_answer: + if op == 'E': + tkinter.messagebox.showerror(title='警告', message='温馨提示,您还有题未作答!') + break + else: + fraction = 0 + for op in range(10): + if standard_answer[number_list[op]] == user_answer[op]: + fraction += 10 + + + conn1 = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8') + cur1 = conn1.cursor() + + # timestamp = int(time.time()) + # time_local = time.localtime(timestamp) + # timetable = time.strftime("%Y-%m-%d %H:%M:%S", time_local) + # search_sqi1 = "set sql_safe_updates=0;" + # cur1.execute(search_sqi1) + # search_sqi1 = "select ExamName from examnation where ExamID=\"" + exam_id + "\";" + # cur1.execute(search_sqi1) + # inf1 = cur1.fetchone() + # search_sqi1 = "insert into studentscore values (\"" + \ + # self.id + "\",\"" + inf1[0] + "\"," + str(fraction) + ",\"" + begin_time + "\"," + "\"" \ + # + timetable + "\");" + timestamp = int(time.time()) + time_local = time.localtime(timestamp) + timetable = time.strftime("%Y-%m-%d %H:%M:%S", time_local) + search_sqi1 = "set sql_safe_updates=0;" + cur1.execute(search_sqi1) + search_sqi1 = "select ExamName from examnation where ExamID=\"" + exam_id + "\";" + cur1.execute(search_sqi1) + inf1 = cur1.fetchone() + search_sqi1 = "insert into studentscore values (\"" + \ + self.id + "\",\"" + inf1[0] + "\"," + str(fraction) + ",\"" + begin_time + "\"," + "\"" \ + + timetable + "\");" + cur1.execute(search_sqi1) + conn1.commit() + cur1.close() + conn1.close() + tkinter.messagebox.showinfo(title='考试结束', message='你的总分是'+str(fraction)+'!') + self.window.pack_forget() + self.window = Frame(self.root) + self.window.pack() + self.flag = 0 + # 将成绩存入数据库并关闭当前答题界面回到学生页面 + + self.window.pack_forget() + self.window = Frame(self.root) + self.window.pack() + count = 1 + maxCount = 10 + + user_answer = [] + for i in range(maxCount): + user_answer.append('E') + + standard_answer = [] + + space_list = [] + + conn = pymysql.connect(host='localhost', user='root', password='123456', db='ruangong', charset='utf8') + + cur = conn.cursor() + + search_sqi = "select * from examnation where ExamID=\"" + exam_id + "\";" + + cur.execute(search_sqi) + + info = cur.fetchone() + + for i in range(4, 14): + search_sqi = "select * from questions where QuesId=\"" + info[i] + "\";" + + cur.execute(search_sqi) + + info1 = cur.fetchone() + + standard_answer.append(info1[7]) + + tab = '\n\t' + + content = info1[2] + tab + info1[3] + tab + info1[4] + tab + info1[5] + tab + info1[6] + + space_list.append(content) + cur.close() + conn.close() + # 此时 space_list 变量存储的才是我们真正想要的题库数据 (数据清洗) + # 随机产生索引 使用set集合是为了不随机产生相同的索引数字 + # 创建一个空集合,用于存储产生不重复的随机数 用作索引题库(space_list) + number_list = [] + while True: + + # 如果number_set的长度等于最大题数,说明产生了我们想要的随机数个数 那就跳出死循环 + if len(number_list) == maxCount: + break + # 将产生的随机数添加到number_list + x = random.randint(0, len(space_list) - 1) + if x not in number_list: + number_list.append(x) + + # 并将产生的新题目存入到paper_list + + paper_list = [] + for i in number_list: + paper_list.append(space_list[i]) + + s = '' + for i in number_list: + s += str(count) + "、" + space_list[i] + s += '\n' + count += 1 + + # 创建滚动条,放到窗口的右侧, 填充Y竖直方向 + main_panedwindow = PanedWindow(self.window, sashrelief=RAISED, sashwidth=20, orient=VERTICAL) + + + # 题目列表区 + course_list_frame1 = Frame() + text = Text(course_list_frame1, width=100, height=25, wrap='char') + text.insert("insert", f'{s}') + text['state'] = 'disabled' + text.pack() + # course_list_frame1.pack(side=LEFT, fill=X, expand=YES) + course_list_frame1.pack(side=TOP, fill=X, padx=5, pady=5, expand=YES, anchor='n') + + # 将数据列表区加入到主窗体 + main_panedwindow.add(course_list_frame1) + + # 定义按钮点击前后颜色 + choicecolor = 'DimGray' + mychoicecolor = 'DeepSkyBlue' + self.window1 = Frame(self.root) + + # 当前所做所做题号,初始化默认为1 + + button1 = Button(self.window1, width=5, text="1", command=lambda: Ques_ABCD(1), bg=choicecolor) + + button2 = Button(self.window1, width=5, text="2", command=lambda: Ques_ABCD(2), bg=choicecolor) + + button3 = Button(self.window1, width=5, text="3", command=lambda: Ques_ABCD(3), bg=choicecolor) + + button4 = Button(self.window1, width=5, text="4", command=lambda: Ques_ABCD(4), bg=choicecolor) + + button5 = Button(self.window1, width=5, text="5", command=lambda: Ques_ABCD(5), bg=choicecolor) + + button6 = Button(self.window1, width=5, text="6", command=lambda: Ques_ABCD(6), bg=choicecolor) + + button7 = Button(self.window1, width=5, text="7", command=lambda: Ques_ABCD(7), bg=choicecolor) + + button8 = Button(self.window1, width=5, text="8", command=lambda: Ques_ABCD(8), bg=choicecolor) + + button9 = Button(self.window1, width=5, text="9", command=lambda: Ques_ABCD(9), bg=choicecolor) + + button10 = Button(self.window1, width=5, text="10", command=lambda: Ques_ABCD(10), bg=choicecolor) + + button1.pack(side=LEFT, padx=10) + + button2.pack(side=LEFT, after=button1, padx=10, pady=5) + + button3.pack(side=LEFT, after=button2, padx=10, pady=5) + + button4.pack(side=LEFT, after=button3, padx=10, pady=5) + + button5.pack(side=LEFT, after=button4, padx=10, pady=5) + + button6.pack(side=LEFT, after=button5, padx=10, pady=5) + + button7.pack(side=LEFT, after=button6, padx=10, pady=5) + + button8.pack(side=LEFT, after=button7, padx=10, pady=5) + + button9.pack(side=LEFT, after=button8, padx=10, pady=5) + + button10.pack(side=LEFT, after=button9, padx=10, pady=5) + + bta = Button(self.window1, width=5, text="A", command=lambda: Choice_change('A'), bg=choicecolor) + + btb = Button(self.window1, width=5, text="B", command=lambda: Choice_change('B'), bg=choicecolor) + + btc = Button(self.window1, width=5, text="C", command=lambda: Choice_change('C'), bg=choicecolor) + + btd = Button(self.window1, width=5, text="D", command=lambda: Choice_change('D'), bg=choicecolor) + + t = "第" + str(self.que_no) + "题选项" + ts = Label(self.window1, width=10, text=t, bg=mychoicecolor) + ts.pack(side=LEFT, padx=10) + # bta.pack(side=LEFT, after=ts, padx=10) + # btb.pack(side=LEFT, after=bta, padx=10, pady=5) + # btc.pack(side=LEFT, after=btb, padx=10, pady=5) + # btd.pack(side=LEFT, after=btc, padx=10, pady=5) + bta.pack(side=LEFT, after=ts, padx=10) + + btb.pack(side=LEFT, after=bta, padx=10, pady=5) + + btc.pack(side=LEFT, after=btb, padx=10, pady=5) + btd.pack(side=LEFT, after=btc, padx=10, pady=5) + Paperover_Confirm = Button(self.window1, width=8, text="提交试卷", bg="red", command=Paperover_Confirm) + Paperover_Confirm.pack(side=LEFT, after=btd, padx=10, pady=5) + main_panedwindow.add(self.window1) + main_panedwindow.pack(fill=BOTH, expand=1) + def SendM(self): + self.window.pack_forget() + self.window = Frame(self.root) + self.window.pack() + + + Label(self.window, text='请输入留言: ', font=('宋体', 15)).grid(row=0, column=0, padx=70, pady=70) + self.MInput = Entry(self.window) + self.MInput.grid(row=0, column=1, padx=75, pady=75) + + Label(self.window, text='请输入收件人: ', font=('宋体', 15)).grid(row=1, column=0, padx=70, pady=70) + self.ReInput = Entry(self.window, show='*') + + self.ReInput.grid(row=1, column=1, padx=75, pady=75) + + Button(self.window, text='确认', width=10, command=self.confirmM, + + font=('宋体', 15)).grid(row=2, column=0, padx=70, pady=70) + def confirmM(self): + + if len(self.MInput.get())==0 or len(len(self.ReInput.get()))==0: + messagebox.showerror(title='提示', message='不允许为空!') + + + else: + messagebox.showinfo(title='提示',message='已发送!') +if __name__ == '__main__': + root = Tk() + StuSc(root, '021154001') + root.mainloop()