|
|
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('<<TreeviewSelect>>')
|
|
|
|
|
|
|
|
|
# 课程列表垂直滚动条
|
|
|
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('<<TreeviewSelect>>')
|
|
|
|
|
|
|
|
|
# 题目列表垂直滚动条
|
|
|
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('<<TreeviewSelect>>')
|
|
|
|
|
|
|
|
|
# 科目列表垂直滚动条
|
|
|
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('<<TreeviewSelect>>', 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('<<TreeviewSelect>>', 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('<<TreeviewSelect>>', 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('<<TreeviewSelect>>', 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("<Button-1>", 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()
|