Newbie needs help with canvas.create_image !
Ok, this is my problem: 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) (Interestingly loop.bmp appears to the red box if I try to pack that canvas.create_image ( canvas.create_image.pack()) and ofcourse I also get an error message that It can't be done. But anyway the picture appears ...weird) -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie needs help with canvas.create_image !
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 -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie needs help with canvas.create_image !
On Sat, 12 Feb 2005 18:24:11 +0100, Fredrik Lundh [EMAIL PROTECTED] 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 -- http://mail.python.org/mailman/listinfo/python-list