Python GUI 程序

部分代码

import tkinter as tk
import tkinter.messagebox
import sqlite3
from tkinter import *

# db = pymysql.connect(host="localhost", port=3306, datebase='diancan_db', user='root', password='123456')
db = sqlite3.connect('diancan.db')
cur = db.cursor()

window = tk.Tk()
window.title('点餐系统 1.0')
window.geometry('500x600')
window.resizable(0, 0)

cv = Canvas(window, width=500, height=600, bg="#B8BFD8")
cv.create_rectangle(150, 95, 450, 440)
cv.pack()
# cv1 = Canvas(window, width=300, height=70, bg="blue")
# cv1.create_rectangle(430,100,430,100)
# cv1.place(x=30,y=470,anchor='nw')

var = tk.StringVar()

label1 = tk.Label(text='欣星餐厅', font=('方正舒体', 28), width=10, height=0, bg="#B8BFD8")
label1.place(x=135, y=10, anchor='nw')

var1 = tk.StringVar()
label2 = tk.Label(width=43, height=4, bg='white', textvariable=var1, wraplength=250, justify=LEFT)
label2.place(x=30, y=470, anchor='nw')

entry1 = tk.Entry(width=25, textvariable=var, font=('楷体', 15))
entry1.place(x=160, y=65, anchor='nw')
buttons = tk.Button(text='搜索', font=('隶书', 13), width=5)
buttons.place(x=420, y=61, anchor='nw')

check_box = []

text = tk.StringVar()
text.set('')
# 渲染
var2 = tk.StringVar()

target_str = []
# def fuc1():
#     if varc.get():
#         check_box.config(text=f'{row[1]}')
def selection():
    get_data = var2.get()
    if get_data:
        print(var2.get())
        if get_data.isdigit():  # name
            cur.execute(f'select * from dishes where num="{var2.get()}"')
            target_str.append(f'{cur.fetchone()[1]} ')
            # target_str.append(' ')
            var1.set(''.join(target_str))
        else:  # discounts_meal
            cur.execute(f'select * from discounts where num="{var2.get()}"')
            # 字符串拼接
            target_str.append(f'{cur.fetchone()[2]}\n')
            # target_str.append('\n')
            var1.set(''.join(target_str))
    else:
        return


def show():
    target_str.pop()
    var1.set(''.join(target_str))


buttone = tk.Button(text='删除', font=('方正舒体', 15), width=8, command=show)
buttone.place(x=30, y=550, anchor='nw')


# def show1():
#     target_str.pop()
#     selection()
#
# buttonh = tk.Button(text = '恢复',font=('方正舒体',15),width=8)
# buttonh.place(x=230,y=550,anchor='nw')
# row = cur.fetchone()
#
# if(var2.get()==1):
#     label2.config(text=f'{row[1]}',bg='red')
# if(var2.get()==0):
#     label2.config(text='none')

def recommended_dishes():
    n = 0
    cur.execute('select * from dishes where tj_class="1"')
    # check_box.append(c)
    row = cur.fetchone()  # (001,黑蒜辣子排骨,98,1,tc1)
    for i in range(len(check_box)):
        check_box[i].config(text='', value='')
        var2.set('')
    while row:
        # 渲染
        check_box[n].config(text=f' {row[1]}'f'{row[2]}''元', bg='white', value=f'{row[0]}', command=selection)
        row = cur.fetchone()
        n += 1


button1 = tk.Button(text='推荐', font=('方正舒体', 18), width=8, height=1, command=recommended_dishes)
button1.place(x=20, y=100, anchor='nw')


def discount_package():
    n = 0
    cur.execute('select * from discounts ')
    # check_box.append(c)
    row = cur.fetchone()  # (001,黑蒜辣子排骨,98,1,tc1)
    for i in range(len(check_box)):
        check_box[i].config(text='', value='')
        var2.set('')
    while row:
        # 渲染
        check_box[n].config(text=f' {row[0]}'f'{row[1]}'f'{row[3]}''元', bg='white', value=f'{row[0]}',command=selection)
        # check_box[n].setvar('oncheck', f'{row[0]}')
        # var2.get()
        row = cur.fetchone()
        n += 1
        # 渲染
        # var2 = tk.IntVar()
        # for i in check_box:
        #     i.config(text=f'{row[0]}'f'{row[1]}'f'{row[3]}''元')
        #     labelt = tk.Label(text=f'{row[2]}', font=('隶书', 12), bg="yellow")
        #     labelt.place(x=160, y=135 + 65 * n, anchor='nw')
        # c = tk.Checkbutton(cv, text=f'{row[0]}'f'{row[1]}'f'{row[3]}''元', font=('隶书', 14),bg="yellow")
        # check_box.append(c)
        # c.place(x=160, y=100 + 67* n, anchor='nw')


button2 = tk.Button(text='优惠套餐', font=('方正舒体', 18), bg='white', width=8, height=1, command=discount_package)
button2.place(x=20, y=170, anchor='nw')


#
def first():
    cur.execute('select * from dishes where tj_class="0" or tj_class="1"')
    row = cur.fetchone()  # (001,黑蒜辣子排骨,98,1,tc1)5
    n = 0
    while row:
        c = tk.Radiobutton(cv, text=f'{row[1]}'f'{row[2]}''元', bg='white', font=('隶书', 12), variable=var2,
                           value=f'{row[0]}', indicatoron=False, width=34, bd=0, command=selection)  # 1没选中,0选中
        c.setvar('oncheck', f'{row[0]}')
        check_box.append(c)
        c.place(x=160, y=100 + 20 * n, anchor='nw')
        row = cur.fetchone()
        n += 1


def dishes():
    n = 0
    # delete_check_box()
    cur.execute('select * from dishes where tj_class="0" or tj_class="1"')
    row = cur.fetchone()  # (001,黑蒜辣子排骨,98,1,tc1)
    for i in range(len(check_box)):
        check_box[i].config(text='')
    while row:
        # 渲染
        check_box[n].config(text=f' {row[1]}'f'{row[2]}''元', bg='white', variable=var2, value=f'{row[0]}',
                            command=selection)
        check_box[n].setvar('oncheck', f'{row[0]}')
        var2.get()
        row = cur.fetchone()
        n += 1


button3 = tk.Button(text='菜品', font=('方正舒体', 18), width=8, height=1, command=dishes)
button3.place(x=20, y=240, anchor='nw')


def drink():
    n = 0
    cur.execute('select * from dishes where tj_class="3"')
    # check_box.append(c)
    row = cur.fetchone()  # (001,黑蒜辣子排骨,98,1,tc1)
    for i in range(len(check_box)):
        check_box[i].config(text='', value='')
        var2.set('')
    while row:
        # 渲染
        check_box[n].config(text=f' {row[1]}'f'{row[2]}''元', bg='white', value=f'{row[0]}', command=selection)
        check_box[n].setvar('oncheck', f'{row[0]}')
        var2.get()
        row = cur.fetchone()
        n += 1


button4 = tk.Button(text='饮品', font=('方正舒体', 18), width=8, height=1, command=drink)
button4.place(x=20, y=310, anchor='nw')


def required():
    n = 0
    cur.execute('select * from dishes where tj_class="2"')
    # check_box.append(c)
    row = cur.fetchone()  # (001,黑蒜辣子排骨,98,1,tc1)
    for i in range(len(check_box)):
        check_box[i].config(text='', value='')
        var2.set('')
    while row:
        # 渲染
        check_box[n].config(text=f' {row[1]}'f'{row[2]}''元', bg='white', value=f'{row[0]}', command=selection)
        check_box[n].setvar('oncheck', f'{row[0]}')
        var2.get()
        row = cur.fetchone()
        n += 1


button5 = tk.Button(text='必选', font=('方正舒体', 18), width=8, height=1, command=required)
button5.place(x=20, y=380, anchor='nw')
first()


def settle_accuonts():
    total_price = 0
    print(target_str)
    for i in target_str:
        if ' ' in i:
            i = i.split(' ')[0]
            cur.execute(f'select price from dishes where name="{i}"')
            total_price += round(float(cur.fetchone()[0]), 2)
            # total_price = 0
            # i = i.split('\n')[0]
            # cur.execute(f'select discounts_price from discounts where discounts_meal="{i}"')
            # total_price += round(float(cur.fetchone()[3]), 2)
        else:
            i = i.split('\n')[0]
            cur.execute(f'select discounts_price from discounts where discounts_meal="{i}"')
            total_price += (cur.fetchone()[0])
            # i = i.split(' ')[0]
            # cur.execute(f'select price from dishes where name="{i}"')
            # total_price += round(float(cur.fetchone()[0]), 2)
    return total_price
#
def messagebox():
    settle_accuonts()
    if settle_accuonts() == 0:
        tk.messagebox.showinfo('Warning', '请点击菜品再进行结算'.format(settle_accuonts()))
    else:
        tk.messagebox.showinfo('Settle Accounts', '您所需支付{}元'.format(settle_accuonts()))


button6 = tk.Button(text='结算', font=('方正舒体', 18), width=8, height=2, bg="#F4E1C1", command=messagebox)
button6.place(x=350, y=470, anchor='nw')
window.mainloop()

"001","黑蒜辣子排骨","梅团优选排骨,每日西班牙空运,纯黑黑蒜,留香持久","98.8"
"002","李庄白肉","老李家传家秘方,李白吃了也叫好,不忍留诗一首","68.8"
"003","软炸虾仁","软糯可口,进口虾仁,纯手工选材,值得信赖","78.8"
"004","金蒜子牛肉粒","精品和牛,热水微烫,肉受轻伤,入口即化","88.8"
"005","香辣扇贝丁","又香又辣,即食即捞,用心培育,吃完小嘴红彤彤","98.8"
"006","香煎小黄鱼","象山专孕小黄鱼,香味四溢,小孩儿口水直流","98.8"
"007","酸爽口味鱼","鲢鱼,在鱼身两面分别打一字花刀,好看的舍不得吃","98.8"
"008","爆炒腰花","绝对的新鲜腰子,优质货源,来源保密","98.8"
"009","肉蟹煲","锅入底油烧至四成热,下入蒜茸,秘方不方便透露","98.8"
"0010","菠萝咕噜日本豆腐","豆腐和菠萝,小日本那边的火热菜品","98.8"
"0011","豆芽菜豆皮卷","豆芽和菜豆和豆皮卷,懂得都懂,没啥说的","98.8"
"0012","醉鸡腿","灌醉小鸡,然后这样那样","98.8"
"0013","橙汁啤酒翅根","这菜很讲究,不好吃打厨师","98.8"

页面展示

选择点餐

选择管理

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值