Reputation: 153
I am making an animated presentation and I want to add an image to it, but I can't use PIL because it will be presented at school, where PIL isn't installed, so I used the method given by the website http://effbot.org/pyfaq/why-do-my-tkinter-images-not-appear.htm, but it doesn't work - my slide is still blank. What should I do?
Here is my code (copied almost completely from the website - did I miss something out?):
photo = PhotoImage('Alveoli.png')
label = Label(image=photo)
label.image = photo # keep a reference!
label.pack()
Upvotes: 0
Views: 1324
Reputation: 835
You can not open .png
files without using an external image library. Since PIL
isn't available I'd think other similar libraries aren't either.
EDIT: Note: PNG
files are supported for tkinter v8.6+
.
The only possibility that comes to mind is converting the image to another, compatible format like GIF
or PGM
If you have the image in one of those formats you can simply add them. It worked just fine for me with this code:
from tkinter import *
root = Tk()
photo = PhotoImage(file="img.ppm")
img = Label(root, image=photo)
img.image = photo
img.place(x=0, y=0)
root.mainloop()
Upvotes: 3