Unfortunately I’m developing under a osx machine where I’ve been unable to install imageTK…
I need to insert an image taken from a dictionary of images, saved thus:
i = open(filename, 'rb')
i.seek(0)
w = i.read()
i.close()
allicons[d]=w
so at insert time I don’t have a filename, just the dict.
with imageTk, this works:
c = cStringIO.StringIO()
c.write(allicons[key])
c.seek(0)
im = Image.open(c)
iconimage=ImageTk.PhotoImage(im)
config.text.image_create(INSERT, image=iconimage)
but I don’t know how to do it without imageTk.
Just with “import Image”, I tried:
im = Image.open(c)
iconimage = PhotoImage(im)
and iconimage is recognized (TkInter.PhotoImage object …),
but inserting it I get a “TypeError: str returned non-string (type instance) … in image_create *self._options(cnf, kw))”
… any help really appreciated, thanks!
alessandro
PhotoImage has a ‘data’ option. You can supply it with gif data that’s been encoded using base64. something like: