Problem with PIL/Tkinter Program Example

Peter Otten __peter__ at
Thu Apr 9 13:01:31 CEST 2009

W. eWatson wrote:

> Something is amiss here. The program produces a canvas in which one can
> move an object around. The input file is hard coded (see open). If you
> want to try it, you'll need to provide a file. Python error below. Name
> space difficulty?

> Traceback (most recent call last):
>    File
> "C
> line 45, in <module>
>      Demo(root)
>    File
> "C
> line 35, in Demo
>      data.img=ImageTk.PhotoImage(img)
> NameError: global name 'ImageTk' is not defined

If you want to use the ImageTk module you have to import it first:

> #Mouse movement
> from Tkinter import *
> import PIL
> import Image

  import ImageTk

[rest of your code here]


More information about the Python-list mailing list