我在下面编写了漂亮的 python 示例代码。现在我该如何做到这一点,当我退出然后重新启动程序时,它会记住刻度的最后位置?
import Tkinter
root = Tkinter.Tk()
root.sclX = Tkinter.Scale(root, from_=0, to=1500, orient='horizontal', resolution=1)
root.sclX.pack(ipadx=75)
root.resizable(False,False)
root.title('Scale')
root.mainloop()
编辑:
我尝试了以下代码
import Tkinter
import cPickle
root = Tkinter.Tk()
root.sclX = Tkinter.Scale(root, from_=0, to=1500, orient='horizontal', resolution=1)
root.sclX.pack(ipadx=75)
root.resizable(False,False)
root.title('Scale')
with open('myconfig.pk', 'wb') as f:
cPickle.dump(f, root.config(), -1)
cPickle.dump(f, root.sclX.config(), -1)
root.mainloop()
但是得到以下错误
Traceback (most recent call last):
File "<string>", line 244, in run_nodebug
File "C:\Python26\pickleexample.py", line 17, in <module>
cPickle.dump(f, root.config(), -1)
TypeError: argument must have 'write' attribute