[Tkinter-discuss] Embedding Inline GIFs

龚强 gq.ciba at gmail.com
Sat Apr 17 06:37:38 CEST 2010


when I make toolbar in my program, I wrote the following code according with
the Python Cookbook,9.6 Embedding Inline GIFs Using Tkinter.

#!/usr/bin/env python
import base64
import Image
import Tkinter
str = "icon='''\n" + base64.encodestring(open("D:\My Documents\My
Pictures\objects_020.gif").read(  )) + "'''"
print str
root = Tkinter.Tk(  )
iconImage = Tkinter.PhotoImage(master=root, format="gif", data=icon)
Tkinter.Button(image=iconImage).pack(  )

I found some gif image would run well with this above codes, but the
others show the following information.

Traceback (most recent call last):
  File "gif.py", line 11, in <module>
    iconImage = Tkinter.PhotoImage(master=root, format="gif", data=icon)
  File "C:\Python26\lib\lib-tk\Tkinter.py", line 3285, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "C:\Python26\lib\lib-tk\Tkinter.py", line 3241, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: error reading color map

what am I doing wrong?
Your help will be greatly appreciated,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20100417/daebab7b/attachment.html>

More information about the Tkinter-discuss mailing list