[Tkinter-discuss] Serializing tkinter objects

willie.lawrence willielawrence1 at gmail.com
Tue Apr 24 19:12:13 CEST 2012


Hello every body!
I think that I can serialize the tkinter objects with this way:

A mode is:

# ------- Encoder.py ------------
import base64, shelve
# The idea is encode the data file to persist, and than decode to read...
pngFile = open("image.png", "rb")
content = pngFile.read()
content.close()
db = shelve.open("Db.db")
db["image"] = base64.b64encode(content)
db.close()

# ------- Reader.py ----------
from Tkinter import *
import ImageTk, shelve, base64
db = shelve.open("DB.db")
content = base64.b64decode(db["image"])
db.close()

top = Tk()
_ph = ImageTk.PhotoImage(data=content)
l = Label(top, image=_ph)
l.grid()
top.mainloop()

--
View this message in context: http://python.6.n6.nabble.com/Serializing-tkinter-objects-tp4902671p4914110.html
Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.


More information about the Tkinter-discuss mailing list