I want to use images in my GUI made with tkinter and python. My problem is that images that i downloaded from Google during the project dosent work and getting the error message is: couldn't recognize data in image file. However old images from before i started the project works, and if it is same type (.png) and in the same folder. I tried with several different folders and they all work with old images, but not with new. This is the method i use:
import tkinter as tk
from tkinter import *
win = tk.Tk()
photo=PhotoImage(file=r'C:\My\Folder\myPicture.png')
photolabel=Label(win, image=photo)
photolabel.pack()
win.mainloop()
tkinter does not recognize all image formats. The safest format for tkinter is .gif; you can try using an image editing program to resave your files as .gifs. Or you can install the pillow module and use that to load images, as that will recognize many more types of images.
py -m pip install pillow
And you would use it like this:
import tkinter as tk
from PIL import Image, ImageTk
win = tk.Tk()
photo=ImageTk.PhotoImage(Image.open(r'C:\My\Folder\myPicture.png'))
photolabel=tk.Label(win, image=photo)
photolabel.pack()
win.mainloop()