diff --git a/src/LoginScreen.py b/src/LoginScreen.py new file mode 100644 index 0000000..fbded1f --- /dev/null +++ b/src/LoginScreen.py @@ -0,0 +1,101 @@ +import tkinter + +from tkinter import * +import tkinter.messagebox +from 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..1a1b961 --- /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 choose(num): + + self.que_no = num + + no = "第" + str(self.que_no) + "题选项" + ts["text"] = no + if user_answer[num - 1] == 'A': + bta["bg"] = gai + btb["bg"] = yuan + btc["bg"] = yuan + btd["bg"] = yuan + elif user_answer[num - 1] == 'B': + bta["bg"] = yuan + btb["bg"] = gai + btc["bg"] = yuan + btd["bg"] = yuan + elif user_answer[num - 1] == 'C': + bta["bg"] = yuan + btb["bg"] = yuan + btc["bg"] = gai + btd["bg"] = yuan + elif user_answer[num - 1] == 'D': + bta["bg"] = yuan + btb["bg"] = yuan + btc["bg"] = yuan + btd["bg"] = gai + else: + bta["bg"] = yuan + btb["bg"] = yuan + btc["bg"] = yuan + btd["bg"] = yuan + + def zt(y): + if y == 'A': + bta["bg"] = gai + btb["bg"] = yuan + btc["bg"] = yuan + btd["bg"] = yuan + elif y == 'B': + bta["bg"] = yuan + btb["bg"] = gai + btc["bg"] = yuan + btd["bg"] = yuan + elif y == 'C': + bta["bg"] = yuan + btb["bg"] = yuan + btc["bg"] = gai + btd["bg"] = yuan + else: + bta["bg"] = yuan + btb["bg"] = yuan + btc["bg"] = yuan + btd["bg"] = gai + user_answer[self.que_no - 1] = y + if self.que_no == 1: + button1["bg"] = gai + elif self.que_no == 2: + button2["bg"] = gai + elif self.que_no == 3: + button3["bg"] = gai + elif self.que_no == 4: + button4["bg"] = gai + elif self.que_no == 5: + button5["bg"] = gai + elif self.que_no == 6: + button6["bg"] = gai + elif self.que_no == 7: + button7["bg"] = gai + elif self.que_no == 8: + button8["bg"] = gai + elif self.que_no == 9: + button9["bg"] = gai + else: + button10["bg"] = gai + + def tj(): + 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) + + # 定义按钮点击前后颜色 + yuan = 'DimGray' + gai = 'DeepSkyBlue' + self.window1 = Frame(self.root) + + # 当前所做所做题号,初始化默认为1 + + button1 = Button(self.window1, width=5, text="1", command=lambda: choose(1), bg=yuan) + + button2 = Button(self.window1, width=5, text="2", command=lambda: choose(2), bg=yuan) + + button3 = Button(self.window1, width=5, text="3", command=lambda: choose(3), bg=yuan) + + button4 = Button(self.window1, width=5, text="4", command=lambda: choose(4), bg=yuan) + + button5 = Button(self.window1, width=5, text="5", command=lambda: choose(5), bg=yuan) + + button6 = Button(self.window1, width=5, text="6", command=lambda: choose(6), bg=yuan) + + button7 = Button(self.window1, width=5, text="7", command=lambda: choose(7), bg=yuan) + + button8 = Button(self.window1, width=5, text="8", command=lambda: choose(8), bg=yuan) + + button9 = Button(self.window1, width=5, text="9", command=lambda: choose(9), bg=yuan) + + button10 = Button(self.window1, width=5, text="10", command=lambda: choose(10), bg=yuan) + + 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: zt('A'), bg=yuan) + + btb = Button(self.window1, width=5, text="B", command=lambda: zt('B'), bg=yuan) + + btc = Button(self.window1, width=5, text="C", command=lambda: zt('C'), bg=yuan) + + btd = Button(self.window1, width=5, text="D", command=lambda: zt('D'), bg=yuan) + + t = "第" + str(self.que_no) + "题选项" + ts = Label(self.window1, width=10, text=t, bg=gai) + 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) + tj = Button(self.window1, width=8, text="提交试卷", bg="red", command=tj) + tj.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()