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.

153 lines
5.7 KiB

import tkinter as tk
from tkinter import ttk
from db import db
class BreadFrame(tk.Frame):
def __init__(self,root):
super().__init__(root)
tk.Label(self, text='该甜品店正在配置中').pack()
class CakeFrame(tk.Frame):
def __init__(self,root):
super().__init__(root)
tk.Label(self, text='蛋糕').pack()
self.table_view = tk.Frame()
self.table_view.pack()
self.create_page()
def create_page(self):
columns = ("name","num","price","id")
columns_values = ("名称", "数量", "价格", "id")
self.tree_view = ttk.Treeview(self,show="headings",columns = columns)
self.tree_view.column('name',width=80,anchor='center')
self.tree_view.column('num', width=80, anchor='center')
self.tree_view.column('price', width=80, anchor='center')
self.tree_view.column('id', width=80, anchor='center')
self.tree_view.heading('name',text='名称')
self.tree_view.heading('num', text='数量')
self.tree_view.heading('price', text='价格')
self.tree_view.heading('id', text='id')
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
students = db.all()
index = 0
for stu in students:
print(stu)
self.tree_view.insert('',index+1,values=(
stu['name'],stu['num'],stu['price'],stu['id'],
))
class ToastFrame(tk.Frame):
def __init__(self, root):
super().__init__(root)
#tk.Label(self, text='吐司').pack()
self.name = tk.StringVar()
self.num = tk.StringVar()
self.price = tk.StringVar()
self.id = tk.StringVar()
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)
tk.Label(self, text='数量').grid(row=2, column=1, pady=10)
tk.Entry(self, textvariable=self.num).grid(row=2, column=2, pady=10)
tk.Label(self, text='价格').grid(row=3, column=1, pady=10)
tk.Entry(self, textvariable=self.price).grid(row=3, column=2, pady=10)
tk.Label(self, text='id').grid(row=4, column=1, pady=10)
tk.Entry(self, textvariable=self.id).grid(row=4, column=2, pady=10)
tk.Button(self, text='查询',command=self.search_user).grid(row=5, column=1, pady=10)
tk.Button(self, text='修改', command=self.change_user).grid(row=5, column=2, pady=10)
tk.Label(self, textvariable=self.status).grid(row=6, column=1, pady=10,stick=tk.E)
def search_user(self):
flag,info=db.search_by_username(self.name.get())
if flag:
self.name.set(info['name'])
self.num.set(info['num'])
self.price.set(info['price'])
self.id.set(info['id'])
self.status.set('数据查询成功')
else:
self.status.set(info)
def change_user(self):
stu = {"name": self.name.get(), "num": self.num.get(), "price": self.price.get(), "id": self.id.get()}
self.name.set('')
self.num.set('')
self.price.set('')
self.id.set('')
db.update(stu)
self.status.set('修改数据成功')
class BiscuitsFrame(tk.Frame):
def __init__(self, root):
super().__init__(root)
#tk.Label(self, text='饼干').pack()
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)
self.status.set(message)
class PuffFrame(tk.Frame):
def __init__(self, root):
super().__init__(root)
self.name = tk.StringVar()
self.num = tk.StringVar()
self.price = tk.StringVar()
self.id = tk.StringVar()
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)
tk.Label(self, text='数量').grid(row=2, column=1, pady=10)
tk.Entry(self, textvariable=self.num).grid(row=2, column=2, pady=10)
tk.Label(self, text='价格').grid(row=3, column=1, pady=10)
tk.Entry(self, textvariable=self.price).grid(row=3, column=2, pady=10)
tk.Label(self, text='id').grid(row=4, column=1, pady=10)
tk.Entry(self, textvariable=self.id).grid(row=4, column=2, pady=10)
tk.Button(self, text='加入',command=self.recode_info).grid(row=5, column=2, pady=10)
tk.Label(self, textvariable=self.status).grid(row=6, column=1, pady=10,stick=tk.E)
def recode_info(self):
stu = {"name": self.name.get(),"num": self.num.get(),"price": self.price.get(),"id": self.id.get()}
self.name.set('')
self.num.set('')
self.price.set('')
self.id.set('')
db.insert(stu)
self.status.set('提交数据成功')