[Tkinter] Unable to load png.

Post here if you need help with creating a Graphical User Interface in Python.

[Tkinter] Unable to load png.

Postby Mekire » Fri Jul 19, 2013 5:53 am

Been fighting with this for awhile now and been through about a dozen stack threads; none of which seem to cover exactly what is going on here.

My error occurs in the following code (occurring in the context of a larger program):
Code: Select all
from PIL import Image,ImageTk
import Tkinter as tk

root = tk.Tk()
image_raw = Image.open('smallface.png')
image = ImageTk.PhotoImage(image_raw)

Trace:
Code: Select all
>>>
Traceback (most recent call last):
  File "C:\Users\Owner\Desktop\tk_test\load_image.py", line 6, in <module>
    image = ImageTk.PhotoImage(image_raw)
  File "C:\Python27\lib\site-packages\PIL\ImageTk.py", line 116, in __init__
    self.paste(image)
  File "C:\Python27\lib\site-packages\PIL\ImageTk.py", line 186, in paste
    tk.call("PyImagingPhoto", self.__photo, block.id)
TclError: destination photo must exist
>>>

I'm using Python 2.7 on a machine running Windows 7. The image is in the same directory as the script.
Anyone have an idea what is going on here?

-Mek
User avatar
Mekire
 
Posts: 816
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: [Tkinter] Unable to load png.

Postby metulburr » Fri Jul 19, 2013 9:10 am

not sure the same works for me. The only difference in me being in linux.
Code: Select all
from PIL import Image,ImageTk
import Tkinter as tk

root = tk.Tk()
image_raw = Image.open('tux.png')
image = ImageTk.PhotoImage(image_raw)

panel1 = tk.Label(root, image=image)
panel1.pack()

root.mainloop()
New Users, Read This
version Python 3.3.2 and 2.7.5, tkinter 8.5, pyqt 4.8.4, pygame 1.9.2 pre
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
User avatar
metulburr
 
Posts: 1102
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY


Return to GUI

Who is online

Users browsing this forum: jimwims and 2 guests