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.

214 lines
8.9 KiB

6 months ago
import tkinter as tk
from tkinter import messagebox
class FootSpaManagementSystem:
def __init__(self,order_info=""):
self.root = tk.Tk() # 创建主窗口
self.root.title("足浴店管理系统")
self.root.geometry("500x300")
self.user_data_file = "user_data.txt" # 用户数据文件路径
self.order_data_file = "order_data.txt" # 订单数据文件路径
self.order_info = order_info
self.create_main_window() # 创建主界面
#初始界面
def create_main_window(self):
self.main_frame = tk.Frame(self.root)
self.main_frame.pack()
self.welcome_label = tk.Label(self.main_frame, text="欢迎使用足浴店管理系统")
self.welcome_label.pack()
self.register_button_main = tk.Button(self.main_frame, text="注册", command=self.switch_to_register)
self.register_button_main.pack()
self.login_button_main = tk.Button(self.main_frame, text="登录", command=self.switch_to_login)
self.login_button_main.pack()
def register_user(self):
username = self.username_entry.get()
password = self.password_entry.get()
if username and password:
with open(self.user_data_file, "a") as file:
file.write(f"{username},{password}\n")
messagebox.showinfo("注册成功", "用户注册成功!") # 显示注册成功信息
else:
messagebox.showerror("注册失败", "请输入用户名和密码。") # 显示注册失败信息
def login_user(self):
username = self.username_entry_login.get()
password = self.password_entry_login.get()
with open(self.user_data_file, "r") as file:
user_data = file.readlines()
for user in user_data:
stored_username, stored_password = user.strip().split(",")
if username == stored_username and password == stored_password:
messagebox.showinfo("登录成功", f"欢迎回来, {username}") # 显示登录成功信息
self.switch_to_order()
return
messagebox.showerror("登录失败", "用户名或密码错误。") # 显示登录失败信息
def surer1(self):
self.frame_register.pack_forget()
self.main_frame.pack()
if hasattr(self, "back_button"):
self.back_button.pack_forget() # 移除返回主界面的按钮
self.frame_register.pack_forget()
self.main_frame.pack()
def surer2(self):
self.frame_order.pack_forget()
self.main_frame.pack()
if hasattr(self, "back_button_order"):
self.back_button_order.pack_forget() # 移除返回主界面的按钮
self.frame_order.pack_forget()
self.main_frame.pack()
#注册界面
def switch_to_register(self):
self.main_frame.pack_forget()
self.frame_register = tk.Frame(self.root)
self.frame_register.pack()
self.username_label = tk.Label(self.frame_register, text="用户名:")
self.username_label.pack()
self.username_entry = tk.Entry(self.frame_register)
self.username_entry.pack()
self.password_label = tk.Label(self.frame_register, text="密码:")
self.password_label.pack()
self.password_entry = tk.Entry(self.frame_register, show="*")
self.password_entry.pack()
self.register_button = tk.Button(self.frame_register, text="注册", command=self.register_user)
self.register_button.pack()
self.back_button = tk.Button(self.root, text="返回主界面", command=self.surer1)
self.back_button.pack()
#登录界面
def switch_to_login(self):
self.main_frame.pack_forget()
self.frame_login = tk.Frame(self.root)
self.frame_login.pack()
self.username_label_login = tk.Label(self.frame_login, text="用户名:")
self.username_label_login.pack()
self.username_entry_login = tk.Entry(self.frame_login)
self.username_entry_login.pack()
self.password_label_login = tk.Label(self.frame_login, text="密码:")
self.password_label_login.pack()
self.password_entry_login = tk.Entry(self.frame_login, show="*")
self.password_entry_login.pack()
self.login_button = tk.Button(self.frame_login, text="登录", command=self.login_user)
self.login_button.pack()
#选择订单界面
def switch_to_order(self):
self.main_frame.pack_forget() # 移除主界面
if hasattr(self, "frame_register"):
self.frame_register.pack_forget() # 移除注册界面(如果存在)
if hasattr(self, "frame_login"):
self.frame_login.pack_forget() # 移除登录界面(如果存在)
self.frame_order = tk.Frame(self.root)
self.frame_order.pack()
self.order_label = tk.Label(self.frame_order, text="请选择服务:")
self.order_label.pack()
self.services = {
"足浴": tk.IntVar(),
"按摩": tk.IntVar(),
"SPA": tk.IntVar(),
"采耳": tk.IntVar()
}
self.foot_spa_checkbox = tk.Checkbutton(self.frame_order, text="足浴", variable=self.services["足浴"])
self.foot_spa_checkbox.pack()
self.massage_checkbox = tk.Checkbutton(self.frame_order, text="按摩", variable=self.services["按摩"])
self.massage_checkbox.pack()
self.spa_checkbox = tk.Checkbutton(self.frame_order, text="SPA", variable=self.services["SPA"])
self.spa_checkbox.pack()
self.ear_cleaning_checkbox = tk.Checkbutton(self.frame_order, text="采耳",variable=self.services["采耳"])
self.ear_cleaning_checkbox.pack()
self.confirm_order_button = tk.Button(self.frame_order, text="确认订单", command=self.confirm_order)
self.confirm_order_button.pack()
self.back_button_order = tk.Button(self.frame_order, text="返回主界面", command=self.surer2)
self.back_button_order.pack()
def confirm_order(self):
selected_services = [service for service, selected in self.services.items() if selected.get() == 1]
if selected_services:
messagebox.showinfo("下单成功", f"您选择了:{', '.join(selected_services)}\n订单信息:{self.order_info}")
# 显示选择技师的界面
self.show_select_technician_screen()
with open(self.order_data_file, "a") as file:
file.write(f"Services: {', '.join(selected_services)}, Order info: {self.order_info}\n")
else:
messagebox.showerror("下单失败", "请选择至少一项服务。")
# 选择技师界面
def show_select_technician_screen(self):
self.frame_order.pack_forget() # 移除选择订单界面
# 创建选择技师的界面
self.frame_technician = tk.Frame(self.root)
self.frame_technician.pack()
self.technician_label = tk.Label(self.frame_technician, text="请选择技师:")
self.technician_label.pack()
self.technicians = {
"6号技师": tk.IntVar(),
"8号技师": tk.IntVar(),
"66号技师": tk.IntVar(),
"88号技师": tk.IntVar(),
}
self.john_doe_checkbox = tk.Checkbutton(self.frame_technician, text="6号技师",
variable=self.technicians["6号技师"])
self.john_doe_checkbox.pack()
self.jane_smith_checkbox = tk.Checkbutton(self.frame_technician, text="8号技师",
variable=self.technicians["8号技师"])
self.jane_smith_checkbox.pack()
self.mike_wilson_checkbox = tk.Checkbutton(self.frame_technician, text="66号技师",
variable=self.technicians["66号技师"])
self.mike_wilson_checkbox.pack()
self.mike_wilson_checkbox = tk.Checkbutton(self.frame_technician, text="88号技师",
variable=self.technicians["88号技师"])
self.mike_wilson_checkbox.pack()
self.confirm_technician_button = tk.Button(self.frame_technician, text="确认技师",
command=self.confirm_technician)
self.confirm_technician_button.pack()
def confirm_technician(self):
selected_technicians = [technician for technician, selected in self.technicians.items() if selected.get() == 1]
if selected_technicians:
technician_message = f"您选择了技师:{', '.join(selected_technicians)}"
messagebox.showinfo("选择技师成功", technician_message)
else:
messagebox.showerror("选择技师失败", "请选择至少一名技师。")
def run(self):
self.root.mainloop() # 启动主循环
# 实例化足浴店管理系统
foot_spa_system = FootSpaManagementSystem()
foot_spa_system.run()