Python Forum
Can't load a png image tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't load a png image tkinter
#1
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()
Reply
#2
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.
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter: An image and label are not appearing. emont 7 410 Mar-21-2024, 03:00 PM
Last Post: deanhystad
  My Background Image Is Not Appearing (Python Tkinter) HailyMary 2 3,981 Mar-14-2023, 06:13 PM
Last Post: deanhystad
  [Tkinter] Load image and show in label ko_fal 8 2,922 Oct-25-2022, 09:20 AM
Last Post: ko_fal
  simple tkinter question function call not opening image gr3yali3n 5 3,305 Aug-02-2022, 09:13 PM
Last Post: woooee
  [Tkinter] Tkinter don't change the image DQT 2 1,562 Jul-22-2022, 10:26 AM
Last Post: menator01
  How to redraw an existing image to a different image TkInter zazas321 6 5,753 Jul-08-2021, 07:44 PM
Last Post: deanhystad
  tkinter showing image in button rwahdan 3 5,528 Jun-16-2021, 06:08 AM
Last Post: Yoriz
  tkinter button image Nick_tkinter 4 3,968 Mar-04-2021, 11:33 PM
Last Post: deanhystad
  how to resize image in canvas tkinter samuelmv30 2 17,560 Feb-06-2021, 03:35 PM
Last Post: joe_momma
  Latex image too big on tkinter using sympy 4096 1 2,891 Nov-05-2020, 08:05 AM
Last Post: DPaul

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020