I’m trying to add an image to a label in Tkinter, but all of the methods I’ve found online, including from the Tk docs, do not work. I keep getting a image “pyimage1” doesn’t exist.
At this point I don’t have any code snippets to share as I don’t have anything down, I just need to know how to use images with Tkinter.
We’re going to need to see some code to help you with the ““pyimage1” doesn’t exist” bit. Have you added the image to the repl? Is the paths to the image correct?
1 Like
It’s added to the repl and the path should be correct as it’s in the same working direction as my main.py. I’ll get you some of the code I tried when I get back on my PC.
1 Like
import tkinter as tk
from PIL import Image, ImageTk
root = tk.Tk()
playFrame = tk.Frame(root)
test = ImageTk.PhotoImage(Image.open("image.png"))
testPhotoList = [test,test,test,test,test,test,test,test,test,test]
scenery = tk.Label(playFrame, image = testPhotoList[0])
scenery.grid(sticky = "NSEW")
playFrame.grid()
1 Like
The error is:
_tkinter.TclError: image “pyimage1” doesn’t exist
For your reference, my repl link is:
https://replit.com/@ThomasWarenski/SDEV-140-Final-Project#main.py
I’ve commented out the troublesome code so I can continue to work on other parts. However, anyone, feel free to copy any and all of my code into your own repl to test it if you think you could help.
Thank you,
Thomas
1 Like