Mr mangaka
Mr mangaka

Reputation: 13

i get an error when trying to add an image to python tkinter

hi so have this image in the same directory as my .py file . and i changed the image from "background.jpg" to "background.gif" because i heard it helps when i hover my cursor over the file=background.gif it show me the image so it can read it but when i try to run . it give me an error and says "couldn't recognize data in image file "background.gif""

from tkinter import *


root = Tk()

photo = PhotoImage(file="background.gif")
label = Label(root, image=photo)
label.pack()

root.mainloop()

code

error

Upvotes: 0

Views: 417

Answers (1)

Delrius Euphoria
Delrius Euphoria

Reputation: 15098

I think the problem here really is(as acw1668 mentioned) because you didn't use an image converter to convert the image, instead just simply renamed the file to .gif, which is not the correct way of changing file formats and can damage the file at times. Using an jpg to gif converter online can clear this issue and give you a gif that works :D

Upvotes: 1

Related Questions