[Tutor] putting an image into a canvas object

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[Tutor] putting an image into a canvas object


What I am trying to do is put an image on a canvas object, which I think is allowed.

self.picture1 = Canvas(self.pictureFrame,width=150,height=150)

self.imageBuffer = StringIO.StringIO()

image = Image.open(filename)
image = image.resize((150,150),Image.ANTIALIAS)
image.save(self.imageBuffer, format= 'PNG')

image = Image.open(self.imageBuffer)

photo = PhotoImage(image)
self.picture1.create_image(0, 0, image = photo )

However, this code results in the following exception:"
Exception in Tkinter callback
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1410, in __call__
    return self.func(*args)
  File "z.py", line 803, in changePicture1
    self.picture1.create_image(0, 0, image = photo )
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 2198, in create_image
    return self._create('image', args, kw)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 2189, in _create
    *(args + self._options(cnf, kw))))
TypeError: __str__ returned non-string (type instance)

What did I do wrong?

Tutor maillist  -  [hidden email]
To unsubscribe or change subscription options: