第一页
开始点餐
import tkinter root2 = tkinter.Tk() root2.title("开始点餐咯") root2.geometry("300x100") screenwidth = root2.winfo_screenwidth() screenheight = root2.winfo_screenheight() widths = 300 heights = 100 x = (screenwidth - widths) / 2 y = (screenheight - heights) / 2 root2.geometry('%dx%d+%d+%d' % (widths, heights, x, y)) # 设置在屏幕中居中显示 start_page = tkinter.Label(root2,text="欢迎来到米其林餐厅") start_page.pack(padx=90,pady=10) start_button = tkinter.Button(root2, text="开始点餐",command=lambda :chnage()) start_button.pack(padx=115, pady=20) def chnage(): root2.destroy() import 点菜界面 点菜界面.root() root2.mainloop()
点菜界面
while True: from tkinter import * import tkinter as tk from tkinter import messagebox import 选位界面 # 菜品和价格字典 menu = { "汉堡": 10, "披萨": 15, "沙拉": 8, "可乐": 5, "雪碧": 5, "牛排": 50, "羊排": 40, "大盘鸡": 45, "寿司": 10, "米饭": 2, "小米粥": 2, "鸡蛋汤": 20, "牛奶": 5, "西瓜汁": 8, "红酒": 60 } # 已点菜品列表 order = [] # 取消循环 def closeWindow(): if messagebox.askyesno("关闭确认","确定要退出选菜系统吗"): exit(0) # 添加菜品 def add_dish(dish): order.append(dish) # 结算清单 def checkout(): # root.destroy() if order: result = "购买清单:\n" total_price = 0 for dish in order: result += dish + " - " + str(menu[dish]) + " 元\n" total_price += menu[dish] result += "总计:" + str(total_price) + " 元\n"+选位界面.opption[0] tk.messagebox.showinfo("结算信息", result) creat_page() else: tk.messagebox.showwarning("提示", "您还没有点任何菜品") # 建立菜单 def show_menu(): menu_window = Toplevel(root) menu_window.title("菜单") screenwidth = menu_window.winfo_screenwidth() screenheight = menu_window.winfo_screenheight() widths = 100 heights = 300 x = (screenwidth - widths) / 3 y = (screenheight - heights) / 2 menu_window.geometry('%dx%d+%d+%d' % (widths, heights, x, y)) # 设置在屏幕中居中显示 for item, price in menu.items(): Label(menu_window, text=f"{item}: {price} 元").pack() # 显示静态的文本或者图像 # 将菜品放入已点菜品列表 def place_order(item): if item in menu: order.append(item) update_order_list() calculate_total() else: messagebox.showerror("错误", "菜品今日无") # 计算总和 def calculate_total(): total = 0 for item in order: total += menu[item] total_label.config(text=f"总金额:{total} 元") # 实时更新点的菜品 def update_order_list(): order_listbox.delete(0, END) for item in order: dish_price = menu[item] order_listbox.insert(END, item + "--" + f"{dish_price}" + '元') # 最后稍等界面 def creat_page(): # t = turtle.Turtle() # t.speed(1) # t.color("red", "pink") new_window = tk.Tk() new_window.geometry("600x300") screenwidth = new_window.winfo_screenwidth() screenheight = new_window.winfo_screenheight() widths = 450 heights = 300 x = (screenwidth - widths) / 2 y = (screenheight - heights) / 2 new_window.geometry('%dx%d+%d+%d' % (widths, heights, x, y)) # 设置在屏幕中居中显示 # t.penup() # t.goto(-20, -20) # t.color("black") # t.pendown() # t.write("点单完成,请等候", font=("Arial", 20, "normal")) # turtle.done() # input() tk.Label(new_window, text="点单完成,请等候......").pack(padx=150, pady=100, fill=BOTH) new_window.protocol('WM_DELETE_WINDOW', closeWindow) back = Button(new_window,text='退出点单',command=closeWindow) back.pack(pady=5,padx=10) restart = Button(new_window, text="追加菜品", command=new_window.destroy) restart.pack(pady=5,padx=15) root.destroy() # 确认订单界面 def confirm_order(): # 添加订单确认对话框 result = messagebox.askyesno("确认订单", "您确定要确认订单吗?") if result: calculate_total() checkout() def remove_dish(): order.clear() order_listbox.delete(0, END) root = Tk() root.title("餐厅点餐系统") root.geometry("600x500") screenwidth = root.winfo_screenwidth() screenheight = root.winfo_screenheight() widths = 600 heights = 500 x = (screenwidth - widths) / 2 y = (screenheight - heights) / 2 root.geometry('%dx%d+%d+%d' % (widths, heights, x, y)) # 设置在屏幕中居中显示 show_menu_button = Button(root, text="查看菜单", command=show_menu) show_menu_button.pack() root.protocol('WM_DELETE_WINDOW', closeWindow) order_listbox = Listbox(root) order_listbox.pack() total_label = Label(root, text="总金额:0 元") total_label.pack() # 模拟菜品按钮 burger_button = Button(root, text="汉堡", command=lambda: place_order("汉堡")) burger_button.place(x=180, y=240) pizza_button = Button(root, text="披萨", command=lambda: place_order("披萨")) pizza_button.place(x=240, y=240) salad_button = Button(root, text="沙拉", command=lambda: place_order("沙拉")) salad_button.place(x=300, y=240) cola_button = Button(root, text="可乐", command=lambda: place_order("可乐")) cola_button.place(x=360, y=240) sprite_button = Button(root, text="雪碧", command=lambda: place_order("雪碧")) sprite_button.place(x=420, y=240) steak_button = Button(root, text="牛排", command=lambda: place_order("牛排")) steak_button.place(x=180, y=280) lamb_button = Button(root, text="羊排", command=lambda: place_order("羊排")) lamb_button.place(x=240, y=280) chicken_button = Button(root, text="大盘鸡", command=lambda: place_order("大盘鸡")) chicken_button.place(x=300, y=280) sushi_button = Button(root, text="寿司", command=lambda: place_order("寿司")) sushi_button.place(x=360, y=280) rice_button = Button(root, text="米饭", command=lambda: place_order("米饭")) rice_button.place(x=420, y=280) porridge_button = Button(root, text="小米粥", command=lambda: place_order("小米粥")) porridge_button.place(x=180, y=320) soup_button = Button(root, text="鸡蛋汤", command=lambda: place_order("鸡蛋汤")) soup_button.place(x=240, y=320) milk_button = Button(root, text="牛奶", command=lambda: place_order("牛奶")) milk_button.place(x=300, y=320) watermelon_button = Button(root, text="西瓜汁", command=lambda: place_order("西瓜汁")) watermelon_button.place(x=360, y=320) wine_button = Button(root, text="红酒", command=lambda: place_order("红酒")) wine_button.place(x=420, y=320) remove_dish = Button(root, text="重新选择菜品", command=remove_dish) remove_dish.place(x=245, y=360) confirm_order_button = Button(root, text="确认订单", command=confirm_order) confirm_order_button.place(x=255, y=400) root.mainloop()
选位界面
import tkinter from tkinter import messagebox desk=["1号桌","2号桌","3号桌","4号桌","5号桌","6号桌","7号桌","8号桌","9号桌","打包回家"] opption=[] root3 = tkinter.Tk() root3.title("选位置") root3.geometry("500x500") screenwidth = root3.winfo_screenwidth() screenheight = root3.winfo_screenheight() widths = 300 heights = 100 x = (screenwidth - widths) / 2 y = (screenheight - heights) / 2 root3.geometry('%dx%d+%d+%d' % (widths, heights, x, y)) # 设置在屏幕中居中显示 start_page = tkinter.Label(root3,text="请选择您的座位") start_page.place(x=100,y=0) start_button = tkinter.Button(root3, text="1号位",command=lambda :place_desk("1号桌")) start_button.place(x=60, y=25) start_button = tkinter.Button(root3, text="2号位",command=lambda :place_desk("2号桌")) start_button.place(x=100, y=25) start_button = tkinter.Button(root3, text="3号位",command=lambda :place_desk("3号桌")) start_button.place(x=140, y=25) start_button = tkinter.Button(root3, text="4号位",command=lambda :place_desk("4号桌")) start_button.place(x=180, y=25) start_button = tkinter.Button(root3, text="5号位",command=lambda :place_desk("5号桌")) start_button.place(x=220, y=25) start_button = tkinter.Button(root3, text="6号位",command=lambda :place_desk("6号桌")) start_button.place(x=60, y=50) start_button = tkinter.Button(root3, text="7号位",command=lambda :place_desk("7号桌")) start_button.place(x=100, y=50) start_button = tkinter.Button(root3, text="8号位",command=lambda :place_desk("8号桌")) start_button.place(x=140, y=50) start_button = tkinter.Button(root3, text="9号位",command=lambda :place_desk("9号桌")) start_button.place(x=180, y=50) start_button = tkinter.Button(root3, text="带回家",command=lambda :place_desk("打包回家")) start_button.place(x=220, y=50) def place_desk(item): if item in desk: opption.append(item) root3.destroy() # import 点菜界面 # 点菜界面.root() root3.mainloop() # # def chnage(): # root3.destroy() # import 点菜界面 # 点菜界面.root() root3.mainloop()