ImageTk.PhotoImage Crash ImageTk.PhotoImage Crash tkinter tkinter

ImageTk.PhotoImage Crash


I've seen that error before using tkinter. I think it had something to do with an older version of tkinter. I updated my python version and tkinter version and it went away. Does this error happen when you run your code on a different OS/Computer/Platform/Version of Python? What version of tkinter are you using? Some google searching revealed these two pages which describe the same bug while using tkinter...

http://osdir.com/ml/python.leo.general/2008-03/msg00060.html
http://fornax.phys.unm.edu/lwa/trac/ticket/3

I can't see all your code, but I'm betting that there is not necessarily anything wrong with your code. The following code worked for me...

from Tkinter import * from PIL import Image, ImageTk # resize image with PILim = Image.open('path to gif')resized_im = im.resize((400,400,),Image.ANTIALIAS)# display image in tkinter windowwindow = Tk()tk_im = ImageTk.PhotoImage(resized_im)window.geometry('%dx%d' % (resized_im.size[0],resized_im.size[1]))label_image = Label(window, image=tk_im)label_image.place(x=0,y=0,width=resized_im.size[0],height=resized_im.size[1])window.mainloop()

Using....
ubuntu 10.04 64 bit
python 2.6.5
python-imaging-tk 1.1.7
python-tk 2.6.5 (which uses version 8.5.0 of tkinter)
python imaging library (PIL) 1.1.7
eclipse 3.7.1
pydev 2.5.0.2012050419

Good luck!


I've been using both Tk, PIL and resizing images for a current project and the following code works fine for me.

#Importsfrom Tkinter import * from PIL import Image, ImageTk #Create Tk instanceroot = Tk()#Open image and resizeimage = Image.open("path/to/image/file").resize((400,400), Image.ANTIALIAS)photo = ImageTk.PhotoImage(image)

After that, I find it easiest to display the images as labels in tkinter like so.

image_label = Label(root, width = 400, height = 400, image = photo bd = 0)

(I like the bd = 0 as otherwise I get a thin white border around the image.)Hope this has helped you. Good luck!Ed


So this is an ancient question, but in case someone stumbles upon this (like I just did), the error message is from Tcl (tclExecute.c). I have no idea what's triggering it, but one thing worth trying is to create a Tk instance before calling PhotoImage:

root = Tk()image = Image.open("0.gif")photo = ImageTk.PhotoImage(image)