(代码备份)低配版点菜生成小票系统

(代码备份)低配版点菜生成小票系统,第1张

(代码备份)低配版点菜生成小票系统

python小白用于备份代码,大佬勿喷

import tkinter as tk
import re
import datetime
import random
import time


# 自定义执行函数, 用于主窗口 确定 键
def run():

    day = datetime.datetime.now()  # 时间
    order_number = random.randint(0, 9999)  # 生成随机单号
    pos_table = random.randint(0, 101)  # 生成随机桌号
    waiter_number = random.randint(0, 50)  # 生成随机服务员号
    winNew = tk.Toplevel(root)              # 子窗口
    winNew.geometry('600x500')              # 子窗口大小
    winNew.title('消费票据')                  # 子窗口标题
    lb_1 = tk.Label(winNew, text='A02-603酒店')         # 一系列基于子窗口的标签
    lb_1.pack()
    lb_2 = tk.Label(winNew, text='客人消费单')
    lb_2.pack()
    lb_3 = tk.Label(winNew, text='----------------------------------------------------------------------')
    lb_3.pack()
    lb_4 = tk.Label(winNew, text='酒店日期: ' + str(day) + '     餐段:午餐')
    lb_4.pack()
    lb_5 = tk.Label(winNew,
                    text='单号: ' + str(order_number) + '   桌号: ' + str(pos_table) + '   服务员:' + str(waiter_number))
    lb_5.pack()
    lb_6 = tk.Label(winNew, text=' ' + '名称'.ljust(15) + ' ' + '数量(份)'.center(15) + ' ' + '单价'.rjust(15) + ' ')
    lb_6.pack()
    lb_7 = tk.Label(winNew, text='----------------------------------------------------------------------')
    lb_7.pack()

    dic_1 = {'油渣炒牛心白': 28, '手剥笋': 25, '回锅肉': 29, '麻婆豆腐': 16, '特价葱香龙利鱼柳': 20, '担担面': 12,
             '米饭': 1, '眉州东坡扣肉': 38, '板栗烧鸡': 49}                                                             # 菜品单价字典
    dic = {0: '', 1: '油渣炒牛心白', 2: '手剥笋', 3: '回锅肉', 4: '麻婆豆腐', 5: '特价葱香龙利鱼柳', 6: '担担面', 7: '米饭',  # 菜品选择字典
           8: '眉州东坡扣肉', 9: '板栗烧鸡'}
    # 变量数的列表
    chk = [var1.get(), var2.get(), var3.get(), var4.get(), var5.get(), var6.get(), var7.get(), var8.get(), var9.get()]
    # 输入值的列表
    input_box = [t1.get(), t2.get(), t3.get(), t4.get(), t5.get(), t6.get(), t7.get(), t8.get(), t9.get()]
    chk_end = []
    input_box_end = []
    for j in chk:
        if j != 0:
            chk_end.append(j)           # 对变量数进行小孩选
    for k in input_box:
        if k != '':
            input_box_end.append(k)
    menu = ''
    for i in chk_end:
        menu += (dic.get(i) + str(input_box[i - 1]))
    lb2.config(text=menu)
    num_list = re.findall("d+.?d*", menu)  # 价格的列表
    b_list = re.compile('[u4e00-u9fa5]+')
    menu_list = b_list.findall(menu)  # 菜名的列表
    total = len(menu_list)  # 菜名列表中元素数
    n = 0
    cost = 0
    while n < total:
        lab10 = tk.Label(winNew, text='|' + str(menu_list[n]).ljust(15) + '|' + str(num_list[n]).center(15) + '|' + str(
            dic_1.get(menu_list[n])).rjust(15) + '|')
        lab10.pack()
        cost += dic_1.get(menu_list[n]) * int(num_list[n])
        n += 1
        if n < total:
            continue
        else:
            lab11 = tk.Label(winNew, text='--------------------------------------------------------------------')
            lab11.pack()
            lab12 = tk.Label(winNew, text='消费合计:'+str(cost))
            lab12.pack()


root = tk.Tk()
root.title('菜单小票系统')
root.geometry('750x840')
var = tk.IntVar()
lab = tk.Label(root, text='菜单')
lab.pack()
foods = ['油渣炒牛心白', '手剥笋', '回锅肉', '麻婆豆腐', '特价葱香龙利鱼柳', '担担面', '米饭',
         '眉州东坡扣肉', '板栗烧鸡']
var1 = tk.IntVar()
var2 = tk.IntVar()
var3 = tk.IntVar()
var4 = tk.IntVar()
var5 = tk.IntVar()
var6 = tk.IntVar()
var7 = tk.IntVar()
var8 = tk.IntVar()
var9 = tk.IntVar()

# 以下为多选按钮的设置
ch1 = tk.Checkbutton(root, text=foods[0], variable=var1, onvalue=1, offvalue=0, indicatoron=False)
ch1.pack(fill='x')
lab1 = tk.Label(root, text='份数')
lab1.pack()
t1 = tk.Entry(root)
t1.pack()

ch2 = tk.Checkbutton(root, text=foods[1], variable=var2, onvalue=2, offvalue=0, indicatoron=False)
ch2.pack(fill='x')
lab2 = tk.Label(root, text='份数')
lab2.pack()
t2 = tk.Entry(root)
t2.pack()

ch3 = tk.Checkbutton(root, text=foods[2], variable=var3, onvalue=3, offvalue=0, indicatoron=False)
ch3.pack(fill='x')
lab3 = tk.Label(root, text='份数')
lab3.pack()
t3 = tk.Entry(root)
t3.pack()

ch4 = tk.Checkbutton(root, text=foods[3], variable=var4, onvalue=4, offvalue=0, indicatoron=False)
ch4.pack(fill='x')
lab4 = tk.Label(root, text='份数')
lab4.pack()
t4 = tk.Entry(root)
t4.pack()

ch5 = tk.Checkbutton(root, text=foods[4], variable=var5, onvalue=5, offvalue=0, indicatoron=False)
ch5.pack(fill='x')
lab5 = tk.Label(root, text='份数')
lab5.pack()
t5 = tk.Entry(root)
t5.pack()

ch6 = tk.Checkbutton(root, text=foods[5], variable=var6, onvalue=6, offvalue=0, indicatoron=False)
ch6.pack(fill='x')
lab6 = tk.Label(root, text='份数')
lab6.pack()
t6 = tk.Entry(root)
t6.pack()

ch7 = tk.Checkbutton(root, text=foods[6], variable=var7, onvalue=7, offvalue=0, indicatoron=False)
ch7.pack(fill='x')
lab7 = tk.Label(root, text='份数')
lab7.pack()
t7 = tk.Entry(root)
t7.pack()

ch8 = tk.Checkbutton(root, text=foods[7], variable=var8, onvalue=8, offvalue=0, indicatoron=False)
ch8.pack(fill='x')
lab8 = tk.Label(root, text='份数')
lab8.pack()
t8 = tk.Entry(root)
t8.pack()

ch9 = tk.Checkbutton(root, text=foods[8], variable=var9, onvalue=9, offvalue=0, indicatoron=False)
ch9.pack(fill='x')
lab9 = tk.Label(root, text='份数')
lab9.pack()
t9 = tk.Entry(root)
t9.pack()

lb2 = tk.Label(root, text='')
lb2.pack()
btn = tk.Button(root, text='确定', command=run)
btn.pack()

root.mainloop()     # 循环显示窗口

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5522170.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-13
下一篇2022-12-13

发表评论

登录后才能评论

评论列表(0条)

    保存