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.

168 lines
5.8 KiB

6 months ago
import tkinter as tk
from tkinter import ttk
from db import db
class AboutFrame(tk.Frame):
def __init__(self,root):
super().__init__(root)
6 months ago
tk.Label(self, text='关于软件基于tkinter开发').pack()
6 months ago
tk.Label(self, text='关于作者:黄晨轲').pack()
6 months ago
tk.Label(self, text='开发时间2024年5月').pack()
6 months ago
class ChangeFrame(tk.Frame):
def __init__(self,root):
super().__init__(root)
self.name = tk.StringVar()
6 months ago
self.banji = tk.StringVar()
self.xuehao = tk.StringVar()
self.youbian = tk.StringVar()
6 months ago
self.status = tk.StringVar()
self.create_page()
def create_page(self):
tk.Label(self).grid(row=0,pady=10)
tk.Label(self,text='姓 名:').grid(row=1, column=1, pady=10)
tk.Entry(self, textvariable=self.name).grid(row=1, column=2, pady=10)
6 months ago
tk.Label(self, text='班 级:').grid(row=2, column=1, pady=10)
tk.Entry(self, textvariable=self.banji).grid(row=2, column=2, pady=10)
6 months ago
6 months ago
tk.Label(self, text='学 号:').grid(row=3, column=1, pady=10)
tk.Entry(self, textvariable=self.xuehao).grid(row=3, column=2, pady=10)
6 months ago
6 months ago
tk.Label(self, text='邮 编:').grid(row=4, column=1, pady=10)
tk.Entry(self, textvariable=self.youbian).grid(row=4, column=2, pady=10)
6 months ago
tk.Button(self, text='查询', command=self.search_user).grid(row=5, column=1, pady=10, stick=tk.E)
tk.Button(self, text='修改',command=self.change_user).grid(row=5, column=2, pady=10,stick=tk.E)
tk.Label(self, textvariable=self.status).grid(row=6, column=2, pady=10)
def search_user(self):
flag, info = db.search_by_username(self.name.get())
if flag:
self.name.set(info['name'])
6 months ago
self.banji.set(info['banji'])
self.xuehao.set(info['xuehao'])
self.youbian.set(info['youbian'])
6 months ago
self.status.set('数据查询成功')
else:
self.status.set(info)
def change_user(self):
6 months ago
stu = {"name": self.name.get(),"banji": self.banji.get(), "xuehao": self.xuehao.get(), "youbian": self.youbian.get()}
6 months ago
self.name.set('')
6 months ago
self.banji.set('')
self.xuehao.set('')
self.youbian.set('')
6 months ago
db.update(stu)
self.status.set('修改数据成功')
class InsertFrame(tk.Frame):
def __init__(self,root):
super().__init__(root)
#tk.Label(self, text='录入页面').pack()
self.name = tk.StringVar()
6 months ago
self.banji = tk.StringVar()
self.xuehao = tk.StringVar()
self.youbian = tk.StringVar()
6 months ago
self.status = tk.StringVar()
self.create_page()
def create_page(self):
tk.Label(self).grid(row=0,pady=10)
tk.Label(self,text='姓 名:').grid(row=1, column=1, pady=10)
tk.Entry(self, textvariable=self.name).grid(row=1, column=2, pady=10)
6 months ago
tk.Label(self, text='班 级:').grid(row=2, column=1, pady=10)
tk.Entry(self, textvariable=self.banji).grid(row=2, column=2, pady=10)
6 months ago
6 months ago
tk.Label(self, text='学 号:').grid(row=3, column=1, pady=10)
tk.Entry(self, textvariable=self.xuehao).grid(row=3, column=2, pady=10)
6 months ago
6 months ago
tk.Label(self, text='邮 编:').grid(row=4, column=1, pady=10)
tk.Entry(self, textvariable=self.youbian).grid(row=4, column=2, pady=10)
6 months ago
tk.Button(self, text='录入',command=self.recode_info).grid(row=5, column=2, pady=10,stick=tk.E)
tk.Label(self, textvariable=self.status).grid(row=6, column=2, pady=10)
def recode_info(self):
6 months ago
stu = {"name": self.name.get(),"banji": self.banji.get(), "xuehao": self.xuehao.get(), "youbian": self.youbian.get()}
6 months ago
self.name.set('')
6 months ago
self.banji.set('')
self.xuehao.set('')
self.youbian.set('')
6 months ago
db.insert(stu)
self.status.set('插入数据成功')
class SearchFrame(tk.Frame):
def __init__(self,root):
super().__init__(root)
self.table_view = tk.Frame()
self.table_view.pack()
self.create_page()
def create_page(self):
6 months ago
coulumns = ("name","xuehao","banji","youbian")
coulumns_values = ("姓名","学号","班级","邮编")
6 months ago
self.tree_view = ttk.Treeview(self, show='headings', columns=coulumns)
self.tree_view.column('name',width=80,anchor='center')
6 months ago
self.tree_view.column('xuehao', width=80, anchor='center')
self.tree_view.column('banji', width=80, anchor='center')
self.tree_view.column('youbian', width=80, anchor='center')
6 months ago
self.tree_view.heading('name',text='姓名')
6 months ago
self.tree_view.heading('xuehao', text='班级')
self.tree_view.heading('banji', text='学号')
self.tree_view.heading('youbian', text='邮编')
6 months ago
self.tree_view.pack(fill=tk.BOTH, expand=True)
self.show_data_frame()
tk.Button(self,text='刷新数据',command=self.show_data_frame).pack(anchor=tk.E,pady=5)
def show_data_frame(self):
#删除旧的阶段
for _ in map(self.tree_view.delete,self.tree_view.get_children('')):
pass
student = db.all()
index = 0
for stu in student:
print(stu)
self.tree_view.insert('',index + 1,values=(
6 months ago
stu['name'],stu['banji'],stu['xuehao'],stu['youbian'],
6 months ago
))
class DeleteFrame(tk.Frame):
def __init__(self,root):
super().__init__(root)
self.username = tk.StringVar()
self.status = tk.StringVar()
tk.Label(self, text='根据名字删除数据').pack()
tk.Entry(self, textvariable=self.username).pack()
tk.Button(self, text='删除',command=self.delete).pack()
tk.Label(self, textvariable=self.status).pack()
def delete(self):
username = self.username.get()
flag,message = db.delete_by_username(username)
6 months ago
self.status.set(message)