Newbie needs help with canvas.create_image !
Arthur
ajsiegel at optonline.com
Sat Feb 12 14:34:13 EST 2005
On Sat, 12 Feb 2005 18:24:11 +0100, "Fredrik Lundh"
<fredrik at pythonware.com> wrote:
>Antti Isomursu wrote:
>
>> With code below I get a red box with given width and height. When I
>> use that create_image, nothing happens. I only see that same red box.
>> Why is that?
>> The loop.bmp is working fine when I use show() method.
>>
>> win = Toplevel()
>>
>> canvas = Canvas(win, width=100, height=100, background='red')
>> canvas.pack()
>>
>> im = Image.open("loop.bmp")
>> photo = ImageTk.PhotoImage(im)
>>
>> canvas.create_image(8, 8, anchor="nw", image=photo)
>
>the problem might be that the PhotoImage is garbage collected before being
>displayed. see the note on the bottom of this page for details:
>
> http://effbot.org/zone/tkinter-photoimage.htm
>
></F>
I had run into this for the first time recently as well.
and found this tutor thread helped.
http://starship.python.net/pipermail/python-de/2002q4/002834.html
Declaring "im" as global is one way to go (there I said it). In fact,
IMO, probably the clearest (though not the prettiest) way to go under
under the circumstances.
I don't think anyone is particularly defending the circumstances. I
have heard the circumstances described as a bug, and the various
"solutions" are perhaps better thought of as work-arounds.
Art
More information about the Python-list
mailing list