I try to display .png file in Tkinter Label, but in effect I get just empty space in place where image should be displayed. It's very simple code and i have no idea what is wrong.
from Tkinter import *
from PIL import Image, ImageTk
root = Tk()
image = Image.open('image.png')
display = ImageTk.PhotoImage(Image.open(image))
label = Label(root, image=display)
label.pack()
root.mainloop()
You're calling Image.open() twice. It's enough to call it once. Use:
display = ImageTk.PhotoImage(image)
instead of:
display = ImageTk.PhotoImage(Image.open(image))
I managed to resolve this problem in this way:
image = Image.open('image.png').convert("RGB")
I'm not sure if it's correct, but it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With