from tkinter import *
import pickle
from tkinter import messagebox
app=Tk()
app.title('仓库系统')
app.geometry('600x400')
var_print=StringVar()
dict1={}
def find_things():
try:
name = l.get(l.curselection())
with open('仓库.pkl', 'rb') as ck:
dict2 = pickle.load(ck)
var_print.set(name + '的数量为 ' + str(dict2[name]) + ' 台')
except:
var_print.set('请点击需要查询的商品')
def out_things():
try:
name=l.get(l.curselection())
def yes_re():
number_1=e.get()
with open('仓库.pkl', 'rb') as ck:
dict2 = pickle.load(ck)
dict2[name] = int(dict2[name]) - int(number_1)
with open('仓库.pkl', 'wb') as ck:
pickle.dump(dict2, ck)
messagebox.showinfo(message='恭喜卖出!生意兴隆!')
a.destroy()
a=Toplevel(app)
a.title('数量')
a.geometry('200x100')
e=Entry(a,width=10,font=('20'))
e.pack()
b_out=Button(a,text='确定',command=yes_re).pack()
except:
messagebox.showinfo(message='请输入')
def in_things():
def save_things():
name=e1.get()
number_thing=e2.get()
if name=='' or number_thing=='':
messagebox.showinfo(message='请检查所输入的信息')
else:
with open('仓库.pkl','rb') as ck:
dict2=pickle.load(ck)
if name in dict2:
dict2[name]=int(dict2[name])+int(number_thing)
else:
dict2[name] = number_thing
l.insert('end', name)
with open('仓库.pkl', 'wb') as ck:
pickle.dump(dict2,ck)
messagebox.showinfo(message='储存成功')
ap.destroy()
ap=Toplevel(app)
ap.title('进货')
ap.geometry('500x300')
Label(ap,text='商品名称',font=(30)).place(x=100,y=90)
Label(ap, text='进货数量', font=(30)).place(x=100, y=150)
e1=Entry(ap,width=25)
e1.place(x=220,y=90)
e2=Entry(ap,width=25)
e2.place(x=220,y=150)
in_b=Button(ap,text='存入系统',font=('KaiTi',15,'bold'),command=save_things)
in_b.place(x=350,y=200)
def delete_things():
name=l.get(l.curselection())
with open('仓库.pkl', 'rb') as ck:
dict2=pickle.load(ck)
del dict2[name]
with open('仓库.pkl', 'wb') as ck:
pickle.dump(dict2, ck)
l.delete(l.curselection())
messagebox.showinfo(message='删除成功')
b1=Button(app,text='查询此商品',command=find_things,font=('KaiTi',20,'bold')).place(x=250,y=160)
b2=Button(app,text='出仓',command=out_things,font=('KaiTi',20,'bold')).place(x=450,y=160)
b3=Button(app,text='进货',command=in_things,font=('KaiTi',20,'bold')).place(x=450,y=220)
b4=Button(app,text='删除该商品',command=delete_things,font=('KaiTi',20,'bold')).place(x=250,y=220)
l1=Label(app,textvariable=var_print,bg='pink',font=('KaiTi',15),width=40,height=3)
l1.place(x=180,y=20)
try:
with open('仓库.pkl', 'rb') as ck:
ck_text = pickle.load(ck)
except:
with open('仓库.pkl', 'wb') as ck:
ck_org = {'无': '无'}
pickle.dump(ck_org, ck)
with open('仓库.pkl', 'rb') as ck:
ck_text = pickle.load(ck)
list1 = list(ck_text.keys())
var=StringVar()
var.set('')
l=Listbox(app,listvariable=var)
for i in range(len(list1)):
l.insert('end',list1[i])
l.place(x=10,y=100)
app.mainloop()