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
  Create image on a Toplevel using tkinter ViktorWong 3 1,169 Jun-13-2020, 03:21 PM
Last Post: deanhystad
  [Tkinter] Tkinter Logo Image Evil_Patrick 1 291 May-25-2020, 05:12 AM
Last Post: DT2000
  tkinter and image paths menator01 2 215 Apr-14-2020, 08:46 PM
Last Post: menator01
  [Tkinter] Image editor using Tkinter and PIL Raulica 2 854 Dec-03-2019, 10:10 PM
Last Post: joe_momma
  Unable to put background image on Tkinter Frame jenkins43 2 3,335 Nov-27-2019, 11:38 AM
Last Post: jenkins43
  Zooming a tkinter image GalaxyCoyote 2 1,983 Nov-09-2019, 04:36 PM
Last Post: GalaxyCoyote
  how to insert image into Text widget Tkinter atlass218 5 3,602 Apr-17-2019, 05:28 AM
Last Post: atlass218
  Display image in tkinter dan789 9 17,169 Dec-09-2018, 08:17 PM
Last Post: dan789
  Tkinter Image Display Weird Tearing Upon Transforming Emerest 6 2,237 Sep-01-2018, 11:46 PM
Last Post: Emerest

Forum Jump:

Users browsing this thread: 1 Guest(s)