Python、数据库课程设计-餐馆点餐系统-连接Mysql数据库-tkinter库实现图形化界面

该点餐系统是基于Mysql数据库的一个点餐系统,用Python自带的数据库库也可实现,该系统可同时作为Python和数据库的课程设计,该系统基于Python,数据库系统主要用于储存数据,具体的数据操作都由Python实现。

本系统数据库部分一共建立了八个表,关系模式如下:

菜谱(菜品编号,菜品名称,菜品类别,菜品价格)∈3NF

顾客(顾客编号,顾客姓名,顾客性别,顾客手机号)∈3NF

餐桌(餐桌号,餐桌座位数,餐桌使用状态,餐桌性质)∈3NF

员工(员工编号,员工姓名,员工性别,员工年龄,员工工资,员工手机号)∈3NF

点餐(订单编号菜品编号,菜品名称,菜品数量)∈3NF

订单(订单编号,顾客编号,消费时间,餐桌号,员工编号)∈3NF

账单(订单编号,消费金额,折扣后金额,消费时间)∈3NF

折扣规则(消费金额,折扣)∈3NF

红色字体的为主键;

以下更清楚的显示了数据库中的内容。具体的代码下载sql文件查看

以下是Python的代码部分:

import pymysql
import tkinter as tk
from tkinter import ttk
from tkinter import messagebox #引入库


conn=pymysql.connect(host='localhost',user='root',password='15115551136',database='cg_manage')
cur=conn.cursor() #连接数据库
Cz_id=''
C_id=''
Z_cai=''
caidan=[]
xuanze=''

def goto1(): #定义子窗口用于输入信息
    def cs(): #输出提示窗提示餐桌的说明
        messagebox.showinfo("餐桌说明","1-2号桌为16人座,3-6号桌为8人座,7-13号桌为4人座") #弹窗
    def on_select1(event): #定义全局变量Cz_id的值,便于后续的数据库数据更新
        global Cz_id #定义全局变量
        Cz_id=C_zuo.get() #全局变量赋值
        print(Cz_id)
    def baocun(): #定义用户信息插入数据库的函数,也更新餐桌信息
        try: #测试用户是否选择空的餐桌号
            cur.execute("select MAX(C_id) from comsumer") #得到下一位顾客的编号
            max=cur.fetchone()
            max=int(max[0])
            count=max
            s=1
            while count//10!=0:
               s+=1
               count/=10
            sql1="update foodtable set Cz_zt='有人' where Cz_id='{}'".format(Cz_id) #餐桌更新指令
            if E_xm.get() and E_xb.get() and E_phone.get(): #判断用户是否输入全部信息
                global C_id
                C_id="{}{}".format((5-s)*'0',str(max+1))
                print(C_id)
                sql2="insert into comsumer values('{}{}','{}','{}','{}')".format((5-s)*'0',str(max+1),E_xm.get(),E_xb.get(),E_phone.get()) #用户信息插入指令
                print(sql1)
                print(sql2)   ###
                #cur.execute(sql1) #执行更新指令
                #cur.execute(sql2) #执行插入指令
                window1.destroy()  #销毁子窗口,用户信息的输入和餐桌的选择完成
            else: #若用户没有输入全部信息,则弹窗提示,重新操作
                messagebox.showwarning("温馨提示","请输入完整的信息")
        except: #没有就弹窗提示,重新操作
            messagebox.showerror("温馨提示!","请先选择餐桌")
    window1=tk.Toplevel() #创建子窗口
    window1.title("欢迎光临") #设置子窗口的标题
    window1.geometry('250x130+1060+440') #窗口大小
    but1=tk.Button(window1,text="退出",command=lambda:window1.destroy()) #设置退出按钮,销毁子窗口
    title=tk.Label(window1,text="请输入个人信息",font=("黑体",10)) 
    b_que=tk.Button(window1,text="确定",command=lambda:baocun()) #设置确定按钮,与baocun函数绑定
    L_xm=tk.Label(window1,text="姓名",font=("黑体",10))
    L_xb=tk.Label(window1,text="性别",font=("黑体",10))
    L_phone=tk.Label(window1,text="电话",font=("黑体",10))
    L_zuowei=tk.Label(window1,text="餐桌",font=("黑体",10))
    B_cs=tk.Button(window1,text="餐桌说明",font=("黑体",10),command=lambda:cs())
    E_xm=tk.Entry(window1) #用户信息输入
    E_xb=tk.Entry(window1)
    E_phone=tk.Entry(window1)
    cur.execute("select * from foodtable") #查询数据库中餐桌的信息
    table=[] 
    for i in cur.fetchall(): #将空的餐桌保存到列表table中
        if i[2]=='空':
            table.append(i[0])
    c=len(table)
    C_zuo=ttk.Combobox(window1,values=table,width=6) #定义下拉框控件,让用户选择餐桌
    C_zuo.bind('<<ComboboxSelected>>', on_select1) #将下拉框的选择绑定on_select函数
    

    #控件布局
    but1.grid(row=4,column=2)
    b_que.grid(row=4,column=1)
    title.grid(row=0,column=1)
    L_xm.grid(row=1,column=0)
    L_xb.grid(row=2,column=0)
    L_phone.grid(row=3,column=0)
    E_xm.grid(row=1,column=1,columnspan=2)
    E_xb.grid(row=2,column=1,columnspan=2)
    E_phone.grid(row=3,column=1,columnspan=2)
    L_zuowei.grid(row=0,column=4)
    C_zuo.grid(row=1,column=4)
    B_cs.grid(row=2,column=4)
    window1.mainloop() #循环
def tianjia1():
    if Cz_id and C_id:
        global Z_cai
        global caidan
        if num1.get() and Z_cai:
            cai="{} 数量:{}".format(Z_cai,num1.get())
            LI_menu.insert("end",cai)
            tishi.set("添加成功")
            caidan.append(Z_cai)
            caidan.append(num1.get())
            print(caidan)
            num1.set(1)
        elif num2.get() and Z_cai:
            cai="{} 数量:{}".format(Z_cai,num2.get())
            LI_menu.insert("end",cai)
            tishi.set("添加成功")
            caidan.append(Z_cai)
            caidan.append(num2.get())
            print(caidan)
            num2.set(1)
        else:
            tishi.set("请输入数量")
        
    else:
        messagebox.showinfo("温馨提示!","点餐请先填写个人信息")
def tianjia2():
    if Cz_id and C_id:
        cai="{} 数量:{}".format()
        LI_menu.insert("end",cai)
        tishi.set("添加成功")
    else:
        messagebox.showinfo("温馨提示!","点餐请先填写个人信息")
def on_select2(event):
    if LI_menu_main.curselection():
        global Z_cai
        Z_cai = LI_menu_main.get(LI_menu_main.curselection())
        print(Z_cai)
def on_select3(event):
    if LI_menu_other.curselection():
        global Z_cai
        Z_cai = LI_menu_other.get(LI_menu_other.curselection())
        print(Z_cai)
def shan():
    try:
        global caidan
        ge=E_shan.get()
        print(ge)
        index=caidan.index(ge)
        index=int(index)
        index1=int(index/2)
        print(index)
        LI_menu.delete(index1,index1)
        caidan.pop(index)
        caidan.pop(index)
        print(caidan)
        tishi.set("删除成功")
    except:
        messagebox.showinfo("温馨提示!","请输入想要删除的菜名")

    
window=tk.Tk() #创建主窗口
window.title("Python 餐馆点餐系统") #设置标题
window.geometry('600x350+440+340') #设置大小
num1=tk.IntVar()
num2=tk.IntVar()
num1.set(1)
num2.set(1)#定义变量
T_main=tk.StringVar()
tishi=tk.StringVar()
T_other=tk.StringVar()
cur.execute("select * from menus") #获得菜单
main=[]
other=[]
for i in cur.fetchall():
    if i[2]=="荤类" or i[2]=="鱼类" or i[2]=="素类" or i[2]=="面类" or i[2]=="汤类" :
        main.append(i[1])
    else:
        other.append(i[1])
main=tuple(main)
other=tuple(other)
T_other.set(other)
T_main.set(main)#给控件送值

but=tk.Button(window,text="个人信息",width=6,height=1,justify='center',command=lambda:goto1()) #定义按钮,绑定goto函数,点击后打开子窗口
but.justify='right' #设置对齐方式
L_huan=tk.Label(window,text="欢迎使用餐馆点餐系统",font=("微软雅黑",20),fg='red',anchor="center") #设置标签
L_diancai=tk.Label(window,text="点菜区",font=("黑体",15),fg='red',justify='center')
L_shan=tk.Label(window,text="请输入你要删除的菜名")
L_xiadan=tk.Label(window,text="您所选择的菜品",font=("黑体",15),fg='red',justify='center')
L_tishi=tk.Label(window,textvariable=tishi,font=("微软雅黑",15),fg='red')
spinbox_num1 = tk.Spinbox(window, from_=0, to=10,width=6,textvariable=num1)
spinbox_num2 = tk.Spinbox(window, from_=0, to=10,width=6,textvariable=num2)#定义列表框控件
LI_menu_main=tk.Listbox(window,listvariable=T_main,width=10) #给列表框控件绑定值
LI_menu_other=tk.Listbox(window,listvariable=T_other,width=10)
LI_menu=tk.Listbox(window,width=40,justify='center')
LI_menu_main.bind('<<ListboxSelect>>', on_select2)
LI_menu_other.bind('<<ListboxSelect>>', on_select3)
E_shan=tk.Entry(window,justify="right")
B_shan=tk.Button(window,text="删除",width=6,height=1,justify="right",command=lambda:shan())
B_jia1=tk.Button(window,text="添加",width=6,height=1,justify="left",command=lambda:tianjia1())
B_jia2=tk.Button(window,text="添加",width=6,height=1,justify="left",command=lambda:tianjia1())


#控件布局
but.grid(row=0,column=0)
B_jia1.grid(row=5,column=0)
B_jia2.grid(row=5,column=2)
B_shan.grid(row=4,column=6)
E_shan.grid(row=4,column=5)
LI_menu_other.grid(row=3,column=0,padx=10)
LI_menu_main.grid(row=3,column=2,padx=5)
LI_menu.grid(row=3,column=4,columnspan=3,padx=50)
spinbox_num1.grid(row=4,column=0)
spinbox_num2.grid(row=4,column=2)
L_shan.grid(row=4,column=4)
L_huan.grid(row=0,column=2,columnspan=4)
L_tishi.grid(row=5,column=4)
L_diancai.grid(row=2,column=0,columnspan=3)
L_xiadan.grid(row=2,column=4,columnspan=3)

window.mainloop() #循环

cur.close() #关闭游标
conn.close() #关闭数据库
  • 5
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值