[Tkinter-discuss] Embedding Inline GIFs

Igor Novikov igor.e.novikov at gmail.com
Sat Apr 17 12:04:48 CEST 2010


Hi,

It seems your GIF file contains features which are not supported by regular
Tcl/Tk
GIF loader. I would recommend you to try using PIL (Python Image Library)
for image uploading.
Also please  note that latest PIL 1.1.7 allows using PNG images with alpha
channel.
I think PNG icons are better then GIF due to full range alpha channel.

Regards,

Igor Novikov
sK1 Project
http://sk1project.org

On Sat, Apr 17, 2010 at 7:37 AM, 龚强 <gq.ciba at gmail.com> wrote:

> Hi,
>
> 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
> exec(str)
> root = Tkinter.Tk(  )
> iconImage = Tkinter.PhotoImage(master=root, format="gif", data=icon)
> Tkinter.Button(image=iconImage).pack(  )
> root.mainloop()
>
> 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,
> Gong.
>
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20100417/4e18ebee/attachment.html>


More information about the Tkinter-discuss mailing list