[Tkinter-discuss] canvas.create_image

Jeff Epler jepler at unpythonic.net
Thu Jun 30 16:59:33 CEST 2005


On Wed, Jun 29, 2005 at 09:50:44PM -0700, Todd Lericos wrote:
> I tried many of the suggested fixes. For example, heading off 
> garbage collection of the image...etc. No dice.

I'm pretty sure you didn't "head off garbage collection of the image".
Here's why:  You immediately discard the MakeGui instance you create,
and it is the only thing which holds a reference to the image.  

Perhaps this change will make your program work:
- MakeGui(tooltitle, filedir, filetype, plotelem, filelist)
+ gui = MakeGui(tooltitle, filedir, filetype, plotelem, filelist)

In fact, in the program below, storing the 'App' instance is what makes
the difference between a program that displays an image and one that
doesn't.

Jeff


import Tkinter
class App:
    def __init__(self, t):
        self.i = Tkinter.PhotoImage(file = "example.gif")
        c = Tkinter.Canvas(t, width=16, height=16); c.pack()
        c.create_image(0, 0, image = self.i, anchor=Tkinter.NW)

t = Tkinter.Tk()

# If this line is used, the program does not work
#App(t)

# If this line is used, the program works
a = App(t)

t.mainloop()

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050630/370af10a/attachment.pgp


More information about the Tkinter-discuss mailing list