Python Forum

Full Version: Can't load a png image tkinter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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()
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.
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.