[Tkinter-discuss] Serializing tkinter objects

willie.lawrence willielawrence1 at gmail.com
Fri Apr 20 19:22:47 CEST 2012


Hello everybody,
I'm a new user of this List.
OBS: forgive my english (I'm a brazilian student)
My question:
I want save PhotoImage (Tkinter.PhotoImage or/and PIL.tkImage.PhotoImage)
objects, but Tkinter classes cannot be serialized, so I thought in get all
pixels and serialize this tuple, when in starting of my program post all
pixels. The problem is that is a harmful practice to velocity...Look, load a
wallpaper of 1600x1200 pixels...

I also try encode the content of file:

# ----------- toEncoder.py -----------
import base64 as b64, shelve
gifFile = open("image.gif", "wb") # loading the gif image
content = gifFile.read()
shelveDB = shelve.open("SimpleDb.db") # where I will save
shelveDB["myGIF"] = b64.b64encode(content)
shelveDB.close()
gifFile.close()
# ----------- EOF -----------

# ----------- reader.py -----------
from Tkinter import *
import shelve
db = shelve.open("SimpleDB.db")
content = db["myGIF"]
top = Tk()
img = PhotoImage()
img.configure(data=content)
testLabel = Label(top, text="test", compound="left", image=img)
testLabel.image = img
testLabel.grid()
db.close()
top.mainloop()
# ----------- EOF -----------
 But, how you can see, I can do it only with GIF Images (using
Tkinter.PhotoImage)
Anyway,
any help is welcome!

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


More information about the Tkinter-discuss mailing list