【发布时间】:2015-12-05 05:19:28
【问题描述】:
我正在制作一个客户列表,我正在使用字典和 pickle 来保存和存储客户的姓名和年龄。不幸的是,我的保存功能会覆盖任何现有用户,然后我的__init__ 功能不会在字典中显示腌制数据,而只会显示我自己输入的数据。 add 函数也不会显示带有客户名称的标签。你能帮忙解决泡菜的问题吗,因为我需要一个快速的答案!
提前致谢!
from Tkinter import *
import pickle
root=Tk()
dic={}
class Launch(object):
def __init__(self, root):
root.withdraw()
root=Toplevel(root)
root.title("Choose Client")
self.row=3
for key in dic:
Label(root, text=key).grid(row=row, column=0)
self.row+=1
l3=Label(root, text="Client Name")
l3.grid(row=0, column=0)
self.e1=Entry(root)
self.e1.grid(row=0, column=1)
l4=Label(root, text="Client age")
l4.grid(row=1, column=0)
self.e2=Entry(root)
self.e2.grid(row=1, column=1)
b3=Button(root, text="Create client", command=self.add)
b3.grid(row=2)
def add(self):
client=self.e1.get()
age=self.e2.get()
dic[client]=age
Label(root, text="%s" % (client)).grid(row=self.row)
with open("data", "w") as f:
pickle.dump(dic, f)
def load(self):
dic=pickle.load(open("data", "rb"))
app=Launch(root)
root.mainloop()
【问题讨论】:
-
如果不继续阅读,你腌制的所有东西都必须是可散列的......是吗?
-
load方法根本没有使用。
标签: python dictionary tkinter pickle