简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM