Python生日系统
#免费源码见文末公众号#
录入生日
def write():key=var1.get()value=var2.get()with open('d:\\生日系统.pickle','rb') as file:dicts=pickle.load(file)dicts[key]=valuewith open('d:\\生日系统.pickle','wb') as file:pickle.dump(dicts,file)file.close()
查询生日
def read():name=var3.get()with open('d:\\生日系统.pickle','rb') as file:dicts=pickle.load(file)file.close()if name in dicts and dicts[name]!='':re=dicts[name]else:re='ERROR!'t.delete(1.0,tk.END)t.insert('end',re)
删除生日
def delete():name=var4.get()with open('d:\\生日系统.pickle','rb') as file:dicts=pickle.load(file)file.close()if name in dicts:del dicts[name]else:passwith open('d:\\生日系统.pickle','wb') as file:pickle.dump(dicts,file)file.close()
界面设计
tk.Label(root,text='欢迎进入生日系统',font=('宋体',12),bg='blue',fg='white',width=20,height=3).place(x=160,y=20) tk.Label(root,text='姓名',font=('宋体',12),bg='white',fg='black').place(x=20,y=100) tk.Label(root,text='生日',font=('宋体',12),bg='white',fg='black').place(x=240,y=100) tk.Label(root,text='姓名',font=('宋体',12),bg='white',fg='black').place(x=20,y=170) tk.Label(root,text='生日',font=('宋体',12),bg='white',fg='black').place(x=240,y=170) tk.Entry(root,textvariable=var1).place(x=80,y=100) tk.Entry(root,textvariable=var2).place(x=300,y=100) tk.Entry(root,textvariable=var3).place(x=80,y=170) tk.Entry(root,textvariable=var4).place(x=150,y=240) t=tk.Text(root,font=('宋体',12),bg='white',fg='black',width=20,height=1) t.place(x=290,y=170) tk.Button(root,text='录入',font=('宋体',12),bg='red',fg='white',command=write).place(x=220,y=130) tk.Button(root,text='查询',font=('宋体',12),bg='yellow',fg='white',command=read).place(x=220,y=200) tk.Button(root,text='删除',font=('宋体',12),bg='black',fg='white',command=delete).place(x=300,y=235)