Bottom Page

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()
Quote
#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.
Quote
#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.
Quote

Top Page

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

Forum Jump:


Users browsing this thread: 1 Guest(s)