【发布时间】:2013-12-30 15:46:43
【问题描述】:
我创建了希望保存在 JSON 或 XML 文件中的对象(使用 tkinter 小部件),以便在启动后恢复它们。
from Tkinter import *
class Texte:
def __init__(self, ax, ay, txt):
self.entry = Entry(root,bd=0,font=("Purisa",int(15)))
self.entry.insert(0, txt)
self.x = ax
self.y = ay
self.entry.place(x=self.x,y=self.y)
root = Tk()
a = Texte(10, 20, 'blah')
b = Texte(20, 70, 'blah2')
# here the user will modify the entries' x, y, txt, etc.
L = [a,b]
# here save the list L (containing the Texte objects) into a JSON file or XML so that I can recover them after restart
root.mainloop()
如何使用 JSON 或 XML 保存和恢复这些对象?
(我现在对http://docs.python.org/2/library/json.html 有点迷茫。)
【问题讨论】:
标签: python xml json serialization tkinter