from tkinter import *
import pyautogui as pg
import pickle
from tkinter import messagebox
import time
from tkinter import colorchooser
from tkinter import PhotoImage
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
x,y=pg.size()
sss=0
ss1=0
def ml0():
global dic,guke_dic,shouyintai_dic,bjys,bjtm
f=open('change.dll','rb')
dic=pickle.load(f)
guke_dic=pickle.load(f)
shouyintai_dic=pickle.load(f)
bjys=pickle.load(f)
bjtm=pickle.load(f)
f.close()
def ml01():
f=open('change.dll','wb')
pickle.dump(dic,f)
pickle.dump(guke_dic,f)
pickle.dump(shouyintai_dic,f)
pickle.dump(bjys,f)
pickle.dump(bjtm,f)
f.close()
def ml1(aaa):
global t1,e3
t1=Toplevel(win1)
kuan=640
gao=400
jdkuan=int(x/2-kuan/2)
jdgao=int(y/2-gao/2)
t1.geometry('{}x{}-{}+{}'.format(kuan,gao,jdkuan,jdgao))
l6=Label(t1,bg=ys)
l6.place(relx=0.0,rely=0.0,relwidth=1,relheight=1)
l7=Label(t1,bg=ys,text='请输入会员卡卡号\n不输入代表无卡',font=('幼圆',25,'bold'))
l7.place(relx=0.0,rely=0.0,relwidth=1,relheight=0.3)
e3=Entry(t1,bg=ys,font=('华文新魏',40),bd=5)
e3.place(relx=0.0,rely=0.3,relwidth=1,relheight=0.3)
e3.focus_set()
e3.bind('<Return>',ml5)
e3.bind('<Escape>',ml1a)
b3=Button(t1,text='确定/enter',font=('华文新魏',25),bg=ys,command=lambda:ml5(1),bd=5)
b3.place(relx=0.3,rely=0.7,relwidth=0.4,relheight=0.2)
def ml1a(event):
t1.destroy()
def ml2():
a=lb1.curselection()
b=lb2.curselection()
c=lb3.curselection()
d=lb4.curselection()
if b!=() or c!=() or d!=():
e=messagebox.showwarning('',' 请选中商品名称进行删除操作 ')
if a!=():
a1=a[0]
lb1.delete(a)
lb2.delete(a1)
lb3.delete(a1)
lb4.delete(a1)
def ml3(event):
if e1.get()!='':
a=var6.get()
if a=='' or a=='无效货号':
messagebox.showwarning('',' 请输入有效货号 ')
e1.focus_set()
else:
e2.focus_set()
else:
messagebox.showwarning('',' 请输入货号 ')
e1.focus_set()
def ml4(a):
global l8,l16,t2,var3,l15
if var1.get()=='':
e1.delete(0,END)
messagebox.showerror('',' 请先输入商品信息 ')
else:
t2=Toplevel(win1)
kuan=1280
gao=800
jdkuan=int(x/2-kuan/2)
jdgao=int(y/2-gao/2)
t2.geometry('{}x{}-{}+{}'.format(kuan,gao,jdkuan,jdgao))
l13=Label(t2,bg=ys)
l13.place(relx=0.0,rely=0.0,relwidth=1,relheight=1)
l8=Label(t2,bg=ys,font=('方正舒体',35))
l8.place(relx=0.0,rely=0.0,relwidth=1,relheight=0.2)
l14=Label(t2,bg=ys,font=('方正舒体',40),text='总金额:')
l14.place(relx=0.0,rely=0.2,relwidth=0.2,relheight=0.3)
var3=StringVar()
l15=Label(t2,bg=ys,font=('黑体',80),fg='red',textvariable=var3)
l15.place(relx=0.2,rely=0.2,relwidth=0.7,relheight=0.3)
var3.set(var1.get())
l16=Label(t2,bg=ys,font=('黑体',35))
l16.place(relx=0.0,rely=0.5,relwidth=1,relheight=0.2)
b1=Button(t2,text='添加会员卡/enter',command=lambda:ml1(t2),font=('华文新魏',30),bg=ys,bd=10)
b1.place(relx=0.05,rely=0.7,relwidth=0.4,relheight=0.2)
b2=Button(t2,text='确认结账/space',font=('华文新魏',30),bg=ys,bd=10,command=lambda:ml10(1))
b2.place(relx=0.55,rely=0.7,relwidth=0.4,relheight=0.2)
e6=Entry(t2,bg=ys,bd=0,fg=ys)
e6.bind('<space>',ml10)
e6.bind('<Return>',ml1)
e6.bind('<Escape>',ml41)
e6.place(relx=0.0,rely=0.0,relwidth=0.01,relheight=0.01)
e6.focus_set()
def ml41(event):
t2.destroy()
def ml5(event):
global sss,ss1,var3
ss1=e3.get().strip()
try:
ss1=int(ss1)
if ss1 in guke_dic.keys():
l8.config(text='卡号: '+str(ss1)+' 有效(已享9折优惠)')
sss=1
ml8()
else:
l8.config(text='卡号 '+str(ss1)+' 无效')
ss1=0
sss=0
var2.set('')
var3.set(var1.get())
l16.config(text='')
except:
if ss1=='':
l8.config(text='无会员卡支付')
ss1=0
sss=0
var2.set('')
var3.set(var1.get())
l16.config(text='')
else:
l8.config(text='卡号 '+str(ss1)+' 无效')
ss1=0
sss=0
var2.set('')
var3.set(var1.get())
l16.config(text='')
t1.destroy()
def ml6(wx=0):
hh=e1.get().strip()
sl=e2.get().strip()
for i in dic.keys():
if hh==i:
try:
ll=float(sl)
lb1.insert(END,dic[i][0])
lb2.insert(END,float(sl))
lb3.insert(END,dic[i][1])
zj=float(sl)*dic[i][1]
lb4.insert(END,zj)
lb5.insert(END,hh)
e1.delete(0,END)
e2.delete(0,END)
e1.focus_set()
break
except:
messagebox.showwarning('',' 请输入有效数量 ')
e2.focus_set()
break
def ml7():
a=lb4.get(0,END)
b=round(sum(a),2)
if b==0:
var1.set('')
else:
var1.set(b)
win1.after(200,ml7)
def ml8():
global var3
a=round(float(var1.get())*0.9,2)
var2.set((a))
var3.set((a))
l16.config(text='原价:'+var1.get())
def ml9():
a=e1.get().strip()
if a=='':
e1.delete(0,END)
var6.set('')
else:
if a in dic.keys():
var6.set(dic[a][0])
else:
var6.set('无效货号')
win1.after(200,ml9)
def ml10(event):
ml11()
lb1.delete(0,END)
lb2.delete(0,END)
lb3.delete(0,END)
lb4.delete(0,END)
lb5.delete(0,END)
e1.delete(0,END)
e2.delete(0,END)
var1.set('')
var2.set('')
t2.destroy()
def ml11():
global sss,ss1,var3
a=lb1.get(0,END)
b=lb2.get(0,END)
d=lb5.get(0,END)
c=list(zip(a,b,d)) #商品,数量,货号
for i in c:
shouyintai_dic[i[2]]=shouyintai_dic.get(i[2],[0,0])
shouyintai_dic[i[2]][0]=i[0]
shouyintai_dic[i[2]][1]=shouyintai_dic.get(i[2])[1]+float(i[1])
dic[i[2]][2]=dic[i[2]][2]-float(i[1])
shouyintai_dic['all']=shouyintai_dic.get('all',0)+float(var3.get())
messagebox.showinfo('',' ✨结账成功🎉 ')
if sss==0 and ss1==0 and float(var3.get())>=200:
k=messagebox.askokcancel('','未持卡顾客一次购物满200元,是否为其发放会员卡?')
if k==1:
ml19()
if sss==1 and ss1!=0:
l=guke_dic[ss1][2]
c=list(zip(a,b,d)) #商品,数量,货号
for i in c:
l[i[2]]=l.get(i[2],[0,0])
l[i[2]][0]=i[0]
l[i[2]][1]=l[i[2]][1]+float(i[1])
try:
guke_dic[ss1][3]=guke_dic[ss1][3]+float(var3.get())
except:
guke_dic[ss1].append(float(var3.get()))
print(guke_dic[ss1])
sss=0
ss1=0
ml01()
ml0()
def ml12():
t4=Toplevel(win1)
t4.title('收银台销售总量')
kuan=1280
gao=800
jdkuan=int(x/2-kuan/2)
jdgao=int(y/2-gao/2)
t4.geometry('{}x{}-{}+{}'.format(kuan,gao,jdkuan,jdgao))
l19=Label(t4,bg=ys)
l19.place(relx=0.0,rely=0.0,relwidth=1,relheight=1)
f6=Frame(t4,bg=ys)
f6.place(relx=0.0,rely=0.0,relwidth=1,relheight=1)
lb7=Listbox(f6,bg=ys,font=('黑体',20))
lb7.place(relx=0.0,rel