from tkinter import *
import pickle
s = open('kuu','rb')
data=pickle.load(s)
s.close()
root = Tk()
root.title('库存管理')
def wz(zhu,gao,kuan):
width = kuan
height = gao
screenwidth = zhu.winfo_screenwidth()
screenheight = zhu.winfo_screenheight()
alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth-width)/2, (screenheight-height)/2)
zhu.geometry(alignstr)
wz(root,250,400)
def aa(ccc,abb,baa):
e1.delete(1.0, END)
e1.insert(INSERT,'%s\n\n\n\n数量:%s台\n\n重量:%sKG'%(ccc,abb,baa))
def number(event):
event = c.get(ACTIVE)
aa(ccc=str(event),abb=data[event][0],baa=data[event][1])
def delet():
del data[c.get(ACTIVE)]
c.delete(0,END)
q1.delete(0,END)
def increase():
top2=Toplevel()
wz(top2,70,160)
x1 = Entry(top2)
x1.grid(row=0,column=0,padx=10,pady=5)
def sh():
hh = x1.get()
data[c.get(ACTIVE)][0] += int(hh)
aa(ccc=str(c.get(ACTIVE)),abb=data[c.get(ACTIVE)][0],baa=data[c.get(ACTIVE)][1])
Button(top2,text="确定",width=8,command=sh)\
.grid(row=1,padx=5,pady=5,column=0,)
def reduce():
top3=Toplevel()
wz(top3,70,160)
v1 = Entry(top3)
v1.grid(row=0,column=0,padx=10,pady=5)
def sho():
vv = v1.get()
data[c.get(ACTIVE)][0] -= int(vv)
aa(ccc=str(c.get(ACTIVE)),abb=data[c.get(ACTIVE)][0],baa=data[c.get(ACTIVE)][1])
Button(top3,text="确定",width=8,command=sho)\
.grid(row=1,padx=5,pady=5,column=0,)
def find(event):
c.delete(0,END)
event = q1.get()
for i in data:
pattern = re.compile(r'%s'%(event),re.I)
if pattern.findall('%s'%(i)):
c.insert(END,i)
def sva():
s=open('kuu','wb')
pickle.dump(data,s)
s.close()
def add():
top1=Toplevel()
wz(top1,160,300)
Label(top1,text='品名:').grid(row=0,column=0)
Label(top1,text='数量:').grid(row=1,column=0)
Label(top1,text='重量:').grid(row=2,column=0)
w1 = Entry(top1)
w2 = Entry(top1)
w3 = Entry(top1)
w1.grid(row=0,column=1,padx=10,pady=5)
w2.grid(row=1,column=1,padx=10,pady=5)
w3.grid(row=2,column=1,padx=10,pady=5)
def show():
data[w1.get()]=[int(w2.get()),int(w3.get())]
sva()
w1.delete(0, END)
w2.delete(0, END)
w3.delete(0, END)
Button(top1,text="保存",width=8,command=show)\
.grid(row=3,padx=10,pady=5,column=0,sticky=E)
top1.mainloop()
e1 =Text(root,width=10,height=8,font=("宋体", 14, "bold") )
e1.grid(row=1,column=2,padx=5,pady=11,sticky=NW)
q1 = Entry(root)
q1.grid(row=0,column=1,padx=10,pady=10)
q1.bind('<KeyRelease>',find)
b1 = Button(root,text='增加',width=10,command=increase)
b1.grid(row=0,column=2,padx=8,pady=8,sticky=EW)
b2 = Button(root,text='减少',width=10,command=reduce)
b2.grid(row=0,column=3,padx=8,pady=8,sticky=EW)
b3 = Button(root,text='保存',width=8,command=sva)
b3.grid(row=1,column=3,padx=8,pady=8,sticky=S)
b4 = Button(root,text='添加',width=8,command=add)
b4.grid(row=1,column=3,padx=8,pady=8,sticky=N)
b5 = Button(root,text='删除',width=8,command=delet)
b5.grid(row=1,column=3,padx=8,pady=8,)
c = Listbox(root)
c.grid(row=1,column=1,padx=10,pady=10)
c.bind('<Button-1>',number)
mainloop()