using the 'data' option on the PhotoImage class of Tkinter

Fredrik Lundh fredrik at
Thu Nov 9 18:10:45 CET 2000

Seung Chan Lim wrote:
> I'm doing the following to load the binary data of a GIF file and trying to
> instantiate a PhotoImage object using that data through its "data" option,
> and I'm having some trouble...
> import Tkinter
> root=Tk()
> f=open("temp.gif","rb")
> pimg=Tkinter.PhotoImage(data=img)
> and I get a
> TclError: couldn't recognize image data
> my GIF file is just a simple gif file saved in Photoshop...

how about "pimg=Tkinter.PhotoImage(file="temp.gif")" ;-)

but assuming you have good reasons for loading the image
in a non-direct way, you can find a hint in the tkinter intro
docs [1]:

    "Read image data from a string. In the current
    version of Tk, this only works for base64-encoded
    GIF files. If the file option is given, this option is

in other words, this should work:


for less convoluted ways to get binary image data into
Tkinter, check out the Python Imaging Library [2]


=> options


More information about the Python-list mailing list