Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Can't load a png image tkinter
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)
home_screen = PhotoImage("home.screen.png")
c.create_image(0, 0, image=home_screen, anchor=NW)

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)
path= 'screen.png'
my_image = PhotoImage(
c.create_image(0,0, image= my_image, anchor= NW)
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.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Tkinter] Image editor using Tkinter and PIL Raulica 2 269 Dec-03-2019, 10:10 PM
Last Post: joe_momma
  Unable to put background image on Tkinter Frame jenkins43 2 784 Nov-27-2019, 11:38 AM
Last Post: jenkins43
  Zooming a tkinter image GalaxyCoyote 2 593 Nov-09-2019, 04:36 PM
Last Post: GalaxyCoyote
  how to insert image into Text widget Tkinter atlass218 5 2,517 Apr-17-2019, 05:28 AM
Last Post: atlass218
  Display image in tkinter dan789 9 12,636 Dec-09-2018, 08:17 PM
Last Post: dan789
  Tkinter Image Display Weird Tearing Upon Transforming Emerest 6 1,738 Sep-01-2018, 11:46 PM
Last Post: Emerest

Forum Jump:

Users browsing this thread: 1 Guest(s)