0

I am trying to load a gif image into my tkinter GUI and I am using PhotoClass().Please note that I am not using any external modules such as PIL.I am using python 3.4. At first I tried a .png image,which is not supported natively.So I changed the image extension to .gif, which (I believe) is supported.

The image is first refrenced here:

img=tk.PhotoImage(file="Image.gif")

And is placed into a Label here:

ImageLabel=tk.Label(root, image=img,)
ImageLabel.grid(row=14,column=1)

The error I receive is:

_tkinter.TclError: couldn't recognize data in image file "Image.gif"

Any help would be greatly appreciated.

Ripseed Oil
  • 77
  • 1
  • 1
  • 8
  • You can't just change the name of a PNG file and expect it to magically become a GIF file, they are quite different file formats. – PM 2Ring Oct 19 '17 at 17:25
  • When I open the image on paint the image seems to be fine. – Ripseed Oil Oct 19 '17 at 17:26
  • Because paint can open many file formats. Did you just change the extension manually? Or do a "Save As"? If you changed the extension manually it will not work. – Mike - SMT Oct 19 '17 at 17:28

1 Answers1

1

You can’t just change the extension to magically convert a file to a different format. Tkinter is expecting GIF data, doesn’t get it, and thus throws the error that the data can’t be recognized. You must give it actual GIF data.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685