Python Forum
Can't load a png image tkinter - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Can't load a png image tkinter (/thread-18070.html)



Can't load a png image tkinter - Pythenx - May-04-2019

I don't get any errors, but the image just won't show up. It just shows a blank window with canvas.

from tkinter import *


root = Tk()
c = Canvas(root, width=1000, height=1000)
c.pack()
home_screen = PhotoImage("home.screen.png")
c.create_image(0, 0, image=home_screen, anchor=NW)

root.mainloop()



RE: Can't load a png image tkinter - joe_momma - May-04-2019

Where's the PIL import in your code?
from tkinter import *
from PIL.ImageTk import PhotoImage
from PIL import Image
 
 
root = Tk()
c = Canvas(root, width=1000, height=1000)
c.pack()
path= 'screen.png'
my_image = PhotoImage(Image.open(path))
c.create_image(0,0, image= my_image, anchor= NW)
 
root.mainloop()
I think that the tkinter Image method only accepts gifs and bitmap x10 type of
images. Not png or jpeg or any other commonly used formats.


RE: Can't load a png image tkinter - woooee - May-04-2019

Lookup ImageTk for Tkinter as it supports more formats. You may have to use ImageMagick/PythonMagick to convert to another format that Tkinter will read.