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

470 lines
22 KiB

import tkinter
from tkinter import *
import tkinter.messagebox as mb
import _sqlite3
# 数据库
# conn = _sqlite3.connect(":memory:")
#连接数据库data.db
conn = _sqlite3.connect("data.db")
c = conn.cursor()
#创建表teachers
# c.execute("create table teachers(id char(20),name char(10),"
# "sex char(10),speciality char(20),Title char(20),date char(20))")
#创建表students
# c.execute("create table students(id char(20),name char(10),"
# "sex char(10),speciality char(20),classno char(20),date char(20))")
#添加教师sql语句
def Insert(id, name, sex, speciality, Title, date):
c.execute('insert into teachers values(?,?,?,?,?,?)', (id, name, sex, speciality, Title, date))
# 提交事务
conn.commit()
#添加学生sql语句
def InsertStudent(id, name, sex, speciality, classno, date):
c.execute('insert into students values(?,?,?,?,?,?)', (id, name, sex, speciality, classno, date))
# 提交事务
conn.commit()
#删除教师sql语句
def Del(id):
c.execute("delete from teachers where id = '%s'" % id)
# 提交事务
conn.commit()
#删除学生sql语句
def DelStudent(id):
c.execute("delete from students where id = '%s'" % id)
# 提交事务
conn.commit()
#修改教师sql语句
def Update(id, name, sex, speciality, Title, date):
c.execute('update teachers set name = (?),sex = (?),speciality = (?),Title = (?),date = (?) where id = (?)',
(name, sex, speciality, Title, date, id))
# 提交事务
conn.commit()
#修改学生sql语句
def UpdateStudent(id, name, sex, speciality, classno, date):
c.execute('update students set name = (?),sex = (?),speciality = (?),classno = (?),date = (?) where id = (?)',
(name, sex, speciality, classno, date, id))
# 提交事务
conn.commit()
#查询教师sql语句
def Serch():
c.execute('select * from teachers')
li = c.fetchall()
return li
#查询学生sql语句
def SerchStudent():
c.execute('select * from students')
li = c.fetchall()
return li
#根据id查询教师sql语句
def Serchone(id):
c.execute("select * from teachers where teachers.id = '%s'" % id)
return c.fetchall()
#根据id查询学生sql语句
def SerchoneStudent(id):
c.execute("select * from students where students.id = '%s'" % id)
return c.fetchall()
#主窗体
class WelcomeFrame(Frame): # 继承Frame类
def __init__(self, name, master=None):
Frame.__init__(self, master)
self.root = master # 定义内部变量root
self.usrname = name
self.createPage()
def createPage(self):
Label(self, text='欢迎管理员'+self.usrname+'登录', font=("黑体", 20)).pack()
#添加教师类
class InputTeacherFrame(Frame): # 继承Frame类
def __init__(self, master=None):
Frame.__init__(self, master)
self.root = master # 定义内部变量root
self.id = StringVar()
self.name = StringVar()
self.sex = StringVar()
self.speciality = StringVar()
self.Title = StringVar()
self.date = StringVar()
self.createPage()
def createPage(self):
Label(self).grid(row=0, stick=W, pady=10)
Label(self, text='工号: ').grid(row=1, stick=W, pady=10)
Entry(self, textvariable=self.id).grid(row=1, column=1, stick=E)
Label(self, text='姓名: ').grid(row=2, stick=W, pady=10)
Entry(self, textvariable=self.name).grid(row=2, column=1, stick=E)
Label(self, text='性别: ').grid(row=3, stick=W, pady=10)
Entry(self, textvariable=self.sex).grid(row=3, column=1, stick=E)
Label(self, text='专业: ').grid(row=4, stick=W, pady=10)
Entry(self, textvariable=self.speciality).grid(row=4, column=1, stick=E)
Label(self, text='职称: ').grid(row=5, stick=W, pady=10)
Entry(self, textvariable=self.Title).grid(row=5, column=1, stick=E)
Label(self, text='入职年月: ').grid(row=6, stick=W, pady=10)
Entry(self, textvariable=self.date).grid(row=6, column=1, stick=E)
Button(self, text='创建教师账号', command=self.AddTeacher).grid(row=8, column=1, stick=E, pady=10)
#添加教师信息
def AddTeacher(self):
id = self.id.get()
name = self.name.get()
sex = self.sex.get()
speciality = self.speciality.get()
Title = self.Title.get()
date = self.date.get()
if id == '' or name == '':
mb.showerror("错误", "信息不能为空!")
else:
Insert(id,name,sex,speciality,Title,date)
mb.showinfo("成功", "新增教师信息成功")
self.id.set('')
self.name.set('')
self.sex.set('')
self.speciality.set('')
self.Title.set('')
self.date.set('')
#添加学生类
class InputStudentFrame(Frame): # 继承Frame类
def __init__(self, master=None):
Frame.__init__(self, master)
self.root = master # 定义内部变量root
self.id = StringVar()
self.name = StringVar()
self.sex = StringVar()
self.speciality = StringVar()
self.classno = StringVar()
self.date = StringVar()
self.createPage()
def createPage(self):
Label(self).grid(row=0, stick=W, pady=10)
Label(self, text='学号: ').grid(row=1, stick=W, pady=10)
Entry(self, textvariable=self.id).grid(row=1, column=1, stick=E)
Label(self, text='姓名: ').grid(row=2, stick=W, pady=10)
Entry(self, textvariable=self.name).grid(row=2, column=1, stick=E)
Label(self, text='性别: ').grid(row=3, stick=W, pady=10)
Entry(self, textvariable=self.sex).grid(row=3, column=1, stick=E)
Label(self, text='专业: ').grid(row=4, stick=W, pady=10)
Entry(self, textvariable=self.speciality).grid(row=4, column=1, stick=E)
Label(self, text='班级: ').grid(row=5, stick=W, pady=10)
Entry(self, textvariable=self.classno).grid(row=5, column=1, stick=E)
Label(self, text='入学时间: ').grid(row=6, stick=W, pady=10)
Entry(self, textvariable=self.date).grid(row=6, column=1, stick=E)
Button(self, text='创建学生账号', command=self.AddStudent).grid(row=8, column=1, stick=E, pady=10)
#添加学生信息
def AddStudent(self):
id = self.id.get()
name = self.name.get()
sex = self.sex.get()
speciality = self.speciality.get()
classno = self.classno.get()
date = self.date.get()
if id == '' or name == '':
mb.showerror("错误", "信息不能为空!")
else:
InsertStudent(id,name,sex,speciality,classno,date)
mb.showinfo("成功", "新增学生信息成功")
self.id.set('')
self.name.set('')
self.sex.set('')
self.speciality.set('')
self.classno.set('')
self.date.set('')
#查询操作类
class QueryFrame(Frame): # 继承Frame类
def __init__(self, master=None):
Frame.__init__(self, master)
self.root = master # 定义内部变量root
self.itemName = StringVar()
self.createPage()
def createPage(self):
Label(self, text='查询界面', font=('华文行楷', 20), fg='purple').pack()
Button(self, text='查询教师', command=self.show_teacher_frame).pack(anchor='center', pady=5)
Button(self, text='查询学生', command=self.show_student_frame).pack(anchor='center', pady=5)
#查询教师信息
def show_teacher_frame(self):
win2 = tkinter.Toplevel()
win2.title('查询教师信息')
win2.geometry('700x300')
sw = win2.winfo_screenwidth()
sh = win2.winfo_screenheight()
win2.geometry('+%d+%d' % ((sw - 500) / 2, (sh - 300) / 2))
# 欢迎语
Label(win2, text='欢迎进入查询页面', font=('华文行楷', 20), fg='purple').pack()
ListB = tkinter.Listbox(win2)
ListB.place(relx=0.3, rely=0.3, anchor='nw', width=350)
li = Serch()
for item in li:
ListB.insert(0, item)
# 按钮
b2 = tkinter.Button(win2, text='退出', width=10, height=3, bg='gray', command=win2.destroy)
b2.place(relx=1, rely=1, anchor='se')
#查询学生信息
def show_student_frame(self):
win2 = tkinter.Toplevel()
win2.title('查询学生信息')
win2.geometry('700x300')
sw = win2.winfo_screenwidth()
sh = win2.winfo_screenheight()
win2.geometry('+%d+%d' % ((sw - 500) / 2, (sh - 300) / 2))
# 欢迎语
Label(win2, text='欢迎进入查询页面', font=('华文行楷', 20), fg='purple').pack()
ListB = tkinter.Listbox(win2)
ListB.place(relx=0.3, rely=0.3, anchor='nw', width=350)
li = SerchStudent()
for item in li:
ListB.insert(0, item)
# 按钮
b2 = tkinter.Button(win2, text='退出', width=10, height=3, bg='gray', command=win2.destroy)
b2.place(relx=1, rely=1, anchor='se')
#修改操作类
class maintainFrame(Frame): # 继承Frame类
def __init__(self, master=None):
Frame.__init__(self, master)
self.root = master # 定义内部变量root
self.id = StringVar()
self.name = StringVar()
self.sex = StringVar()
self.speciality = StringVar()
self.Title = StringVar()
self.classno = StringVar()
self.date = StringVar()
self.createPage()
def createPage(self):
Label(self, text='信息维护界面', font=('华文行楷', 20), fg='purple').pack()
Button(self, text='修改教师', command=self.update_teacher_frame).pack(anchor='center', pady=5)
Button(self, text='删除教师', command=self.del_teacher_frame).pack(anchor='center', pady=5)
Button(self, text='修改学生', command=self.update_student_frame).pack(anchor='center', pady=5)
Button(self, text='删除学生', command=self.del_student_frame).pack(anchor='center', pady=5)
#修改教师信息
def update_teacher_frame(self):
def update_show():
li = Serchone(id.get())
if len(li) == 0:
tkinter.messagebox.showerror("查询失败", "此教师不存在")
win4.destroy()
pth = li[0]
print(pth)
tkinter.Label(win4, text='%s' % pth[1]).place(relx=0.65, rely=0.22, anchor='center')
tkinter.Label(win4, text='%s' % pth[2]).place(relx=0.65, rely=0.32, anchor='center')
tkinter.Label(win4, text='%s' % pth[3]).place(relx=0.65, rely=0.42, anchor='center')
tkinter.Label(win4, text='%s' % pth[4]).place(relx=0.65, rely=0.52, anchor='center')
tkinter.Label(win4, text='%s' % pth[5]).place(relx=0.69, rely=0.63, anchor='center')
def UpdateDate():
Update(id.get(),name.get(),sex.get(),speciality.get(),Title.get(),date.get())
tkinter.messagebox.showerror("成功", "修改成功")
win4.destroy()
# 设置窗口位置
# 不能使用两次Tk去创建窗体因为tkinter中只能有一个主线程
win4 = tkinter.Toplevel()
win4.title('修改教师信息')
win4.geometry('500x400')
sw = win4.winfo_screenwidth()
sh = win4.winfo_screenheight()
win4.geometry('+%d+%d' % ((sw - 500) / 2, (sh - 300) / 2))
# 欢迎语
l = tkinter.Label(win4, text='欢迎进入修改页面', font=('华文行楷', 20), fg='purple')
l.place(relx=0.5, rely=0.05, anchor='center')
id = tkinter.StringVar()
name = tkinter.StringVar()
sex = tkinter.StringVar()
speciality = tkinter.StringVar()
Title = tkinter.StringVar()
date = tkinter.StringVar()
tkinter.Label(win4, text='工号:').place(relx=0.4, rely=0.12, anchor='center')
tkinter.Entry(win4, textvariable=id).place(relx=0.45, rely=0.1, width=70)
#姓名输入框
tkinter.Label(win4, text='姓名:').place(relx=0.4, rely=0.22, anchor='center')
tkinter.Entry(win4, textvariable=name).place(relx=0.45, rely=0.2, width=70)
# 性别输入框
tkinter.Label(win4, text='性别:').place(relx=0.4, rely=0.32, anchor='center')
tkinter.Entry(win4, textvariable=sex).place(relx=0.45, rely=0.3, width=70)
# 专业输入框
tkinter.Label(win4, text='专业:').place(relx=0.4, rely=0.42, anchor='center')
tkinter.Entry(win4, textvariable=speciality).place(relx=0.45, rely=0.4, width=70)
# 职称输入框
tkinter.Label(win4, text='职称:').place(relx=0.4, rely=0.52, anchor='center')
tkinter.Entry(win4, textvariable=Title).place(relx=0.45, rely=0.5, width=70)
# 入职年月输入框
tkinter.Label(win4, text='入职年月:').place(relx=0.36, rely=0.62, anchor='center')
tkinter.Entry(win4, textvariable=date).place(relx=0.45, rely=0.6, width=70)
# 按钮
tkinter.Button(win4, text='查询', width=10, height=3, bg='gray', command=update_show).place(relx=0, rely=1, anchor='sw')
tkinter.Button(win4, text='确认修改', width=10, height=3, bg='gray', command=UpdateDate).place(relx=0.15, rely=1, anchor='sw')
tkinter.Button(win4, text='退出', width=10, height=3, bg='gray', command=win4.destroy).place(relx=1, rely=1, anchor='se')
#删除教师信息
def del_teacher_frame(self):
def show():
li = Serchone(id.get())
if len(li) == 0:
tkinter.messagebox.showerror("错误", "此教师不存在")
win3.destroy()
pth = li[0]
print(pth)
tkinter.Label(win3, text='%s' % pth[1]).place(relx=0.5, rely=0.2, anchor='center')
tkinter.Label(win3, text='%s' % pth[2]).place(relx=0.5, rely=0.3, anchor='center')
tkinter.Label(win3, text='%s' % pth[3]).place(relx=0.5, rely=0.4, anchor='center')
tkinter.Label(win3, text='%s' % pth[4]).place(relx=0.5, rely=0.5, anchor='center')
tkinter.Label(win3, text='%s' % pth[5]).place(relx=0.55, rely=0.6, anchor='center')
def delDate():
Del(id.get())
tkinter.messagebox.showerror("成功", "删除成功")
win3.destroy()
# 设置窗口位置
# 不能使用两次Tk去创建窗体因为tkinter中只能有一个主线程
win3 = tkinter.Toplevel()
win3.title('删除教师信息')
win3.geometry('500x400')
sw = win3.winfo_screenwidth()
sh = win3.winfo_screenheight()
win3.geometry('+%d+%d' % ((sw - 500) / 2, (sh - 300) / 2))
# 欢迎语
l = tkinter.Label(win3, text='欢迎进入删除页面', font=('华文行楷', 20), fg='purple')
l.place(relx=0.5, rely=0.05, anchor='center')
# 工号输入框
# id = self.id.get()
id = tkinter.StringVar()
tkinter.Label(win3, text='工号:').place(relx=0.4, rely=0.12, anchor='center')
tkinter.Entry(win3, textvariable=id).place(relx=0.45, rely=0.1, width=70)
#姓名展示框
tkinter.Label(win3, text='姓名:').place(relx=0.4, rely=0.2, anchor='center')
# 性别展示框
tkinter.Label(win3, text='性别:').place(relx=0.4, rely=0.3, anchor='center')
# 专业展示框
tkinter.Label(win3, text='专业:').place(relx=0.4, rely=0.4, anchor='center')
# 职称展示框
tkinter.Label(win3, text='职称:').place(relx=0.4, rely=0.5, anchor='center')
# 入职年月展示框
tkinter.Label(win3, text='入职年月:').place(relx=0.4, rely=0.6, anchor='center')
# 按钮
tkinter.Button(win3, text='查询', width=10, height=3, bg='gray', command=show).place(relx=0, rely=1, anchor='sw')
tkinter.Button(win3, text='确认删除', width=10, height=3, bg='gray', command=delDate).place(relx=0.15, rely=1, anchor='sw')
tkinter.Button(win3, text='退出', width=10, height=3, bg='gray', command=win3.destroy).place(relx=1, rely=1, anchor='se')
#修改学生信息
def update_student_frame(self):
def student_show():
li = SerchoneStudent(id.get())
if len(li) == 0:
tkinter.messagebox.showerror("查询失败", "此学生不存在")
win4.destroy()
pth = li[0]
print(pth)
tkinter.Label(win4, text='%s' % pth[1]).place(relx=0.65, rely=0.22, anchor='center')
tkinter.Label(win4, text='%s' % pth[2]).place(relx=0.65, rely=0.32, anchor='center')
tkinter.Label(win4, text='%s' % pth[3]).place(relx=0.73, rely=0.42, anchor='center')
tkinter.Label(win4, text='%s' % pth[4]).place(relx=0.65, rely=0.52, anchor='center')
tkinter.Label(win4, text='%s' % pth[5]).place(relx=0.69, rely=0.63, anchor='center')
def UpdateDate():
UpdateStudent(id.get(),name.get(),sex.get(),speciality.get(),classno.get(),date.get())
tkinter.messagebox.showerror("成功", "修改成功")
win4.destroy()
# 设置窗口位置
# 不能使用两次Tk去创建窗体因为tkinter中只能有一个主线程
win4 = tkinter.Toplevel()
win4.title('修改学生信息')
win4.geometry('500x400')
sw = win4.winfo_screenwidth()
sh = win4.winfo_screenheight()
win4.geometry('+%d+%d' % ((sw - 500) / 2, (sh - 300) / 2))
# 欢迎语
l = tkinter.Label(win4, text='欢迎进入修改页面', font=('华文行楷', 20), fg='purple')
l.place(relx=0.5, rely=0.05, anchor='center')
id = tkinter.StringVar()
name = tkinter.StringVar()
sex = tkinter.StringVar()
speciality = tkinter.StringVar()
classno = tkinter.StringVar()
date = tkinter.StringVar()
# 学号输入框
tkinter.Label(win4, text='学号:').place(relx=0.4, rely=0.12, anchor='center')
tkinter.Entry(win4, textvariable=id).place(relx=0.45, rely=0.1, width=70)
#姓名输入框
tkinter.Label(win4, text='姓名:').place(relx=0.4, rely=0.22, anchor='center')
tkinter.Entry(win4, textvariable=name).place(relx=0.45, rely=0.2, width=70)
# 性别输入框
tkinter.Label(win4, text='性别:').place(relx=0.4, rely=0.32, anchor='center')
tkinter.Entry(win4, textvariable=sex).place(relx=0.45, rely=0.3, width=70)
# 专业输入框
tkinter.Label(win4, text='专业:').place(relx=0.4, rely=0.42, anchor='center')
tkinter.Entry(win4, textvariable=speciality).place(relx=0.45, rely=0.4, width=70)
# 班级输入框
tkinter.Label(win4, text='班级:').place(relx=0.4, rely=0.52, anchor='center')
tkinter.Entry(win4, textvariable=classno).place(relx=0.45, rely=0.5, width=70)
# 入学时间输入框
tkinter.Label(win4, text='入学时间:').place(relx=0.36, rely=0.62, anchor='center')
tkinter.Entry(win4, textvariable=date).place(relx=0.45, rely=0.6, width=70)
# 按钮
tkinter.Button(win4, text='查询', width=10, height=3, bg='gray', command=student_show).place(relx=0, rely=1, anchor='sw')
tkinter.Button(win4, text='确认修改', width=10, height=3, bg='gray', command=UpdateDate).place(relx=0.15, rely=1, anchor='sw')
tkinter.Button(win4, text='退出', width=10, height=3, bg='gray', command=win4.destroy).place(relx=1, rely=1, anchor='se')
#删除学生信息
def del_student_frame(self):
def show():
li = SerchoneStudent(id.get())
if len(li) == 0:
tkinter.messagebox.showerror("错误", "此学生不存在")
win3.destroy()
pth = li[0]
print(pth)
tkinter.Label(win3, text='%s' % pth[1]).place(relx=0.5, rely=0.2, anchor='center')
tkinter.Label(win3, text='%s' % pth[2]).place(relx=0.5, rely=0.3, anchor='center')
tkinter.Label(win3, text='%s' % pth[3]).place(relx=0.5, rely=0.4, anchor='center')
tkinter.Label(win3, text='%s' % pth[4]).place(relx=0.5, rely=0.5, anchor='center')
tkinter.Label(win3, text='%s' % pth[5]).place(relx=0.55, rely=0.6, anchor='center')
def delDate():
DelStudent(id.get())
tkinter.messagebox.showerror("成功", "删除成功")
win3.destroy()
# 设置窗口位置
# 不能使用两次Tk去创建窗体因为tkinter中只能有一个主线程
win3 = tkinter.Toplevel()
win3.title('删除学生信息')
win3.geometry('500x400')
sw = win3.winfo_screenwidth()
sh = win3.winfo_screenheight()
win3.geometry('+%d+%d' % ((sw - 500) / 2, (sh - 300) / 2))
# 欢迎语
l = tkinter.Label(win3, text='欢迎进入删除页面', font=('华文行楷', 20), fg='purple')
l.place(relx=0.5, rely=0.05, anchor='center')
# 学号输入框
id = tkinter.StringVar()
tkinter.Label(win3, text='学号:').place(relx=0.4, rely=0.12, anchor='center')
tkinter.Entry(win3, textvariable=id).place(relx=0.45, rely=0.1, width=70)
#姓名展示框
tkinter.Label(win3, text='姓名:').place(relx=0.4, rely=0.2, anchor='center')
# 性别展示框
tkinter.Label(win3, text='性别:').place(relx=0.4, rely=0.3, anchor='center')
# 专业展示框
tkinter.Label(win3, text='专业:').place(relx=0.4, rely=0.4, anchor='center')
# 班级展示框
tkinter.Label(win3, text='班级:').place(relx=0.4, rely=0.5, anchor='center')
# 入学日期展示框
tkinter.Label(win3, text='入学日期:').place(relx=0.4, rely=0.6, anchor='center')
# 按钮
tkinter.Button(win3, text='查询', width=10, height=3, bg='gray', command=show).place(relx=0, rely=1, anchor='sw')
tkinter.Button(win3, text='确认删除', width=10, height=3, bg='gray', command=delDate).place(relx=0.15, rely=1, anchor='sw')
tkinter.Button(win3, text='退出', width=10, height=3, bg='gray', command=win3.destroy).place(relx=1, rely=1, anchor='se')
#修改密码类
class UpdateKeywordFrame(Frame): # 继承Frame类
def __init__(self, master=None):
Frame.__init__(self, master)
self.root = master # 定义内部变量root
self.createPage()
def createPage(self):
Label(self, text='更新密码界面').pack()