1
votes

I have a simple GUI program I'm building with Tkinter. I want to have a bunch of buttons with app images on them that, when clicked, launch that app. The problem is, Python can't recognise the Skype.gif file.

Code:

from tkinter import *
import os

def open_skype():
    os.system('open /Applications/Skype.app')

master = Tk()

photo = PhotoImage(file='/Users/michael/Desktop/Skype.gif')

but = Button(master, image=photo, command=open_skype)



objs = [but]

column = 1
for i in objs:
    i.grid(column=column, row=1)
    column += 1
mainloop()

Error message:

_tkinter.TclError: couldn't recognize data in image file "/Users/michael/Desktop/Skype.gif"

4
Use image in PNG or JPG format.furas
I tried those and I got the same error: _tkinter.TclError: couldn't recognize data in image file "/Users/michael/Desktop/Skype.png"woff
How did you convert it from GIF to PNG ? Can you see this image in some image viewer ?furas
Definitely converted it, and it isn't corrupt.woff
Can you see this image in some image viewer ?furas

4 Answers

0
votes

Your problem is most likely that the image is not in the correct place. TO ensure that it is, try entering your command line (Terminal for Macs), and typing in ls /Users/michael/Desktop/Skype.gif. If prints Skype.gif or /Users/michael/Desktop/Skype.gif, then the file is there, otherwise it is not.

0
votes

The path starts at where the python file is located so if they're in the same folder just put photo = PhotoImage(file='Skype.gif')

0
votes

Tkinter only recognize s PNG images or JPG images in some cases. If you have a gif image you can incorporate it by using another module called WxPython. How this works is that it uses Frame by frame images to display a video type image. Tkinter does not support this.

0
votes

Make sure your image is in the format of PNG or JPG