TK and PhotoImage: Problem getting image to display
Fredrik Lundh
effbot at telia.com
Thu Feb 24 10:26:21 EST 2000
Kevin Cazabon <kcazabon at home.com> wrote:
> The first thing I'd do is the following:
> > class Quoter:
> > def __init__(self, master):
> > self.qFrame = Frame(master)
> > self.qFrame.pack(side=TOP)
> >
> > #qCompanyLogoCanvas = Canvas(qFrame, width=275, height=50)
> > #qCompanyLogoCanvas.pack(side=LEFT)
> >
> > self.img = PhotoImage(file='amos3.gif')
> > self.qAMOSLogoCanvas = Canvas(qFrame, width=300, height=300)
> > self.qAMOSLogoCanvas.create_image(0, 0, anchor=NW,
image=self.img)
> > self.qAMOSLogoCanvas.pack()
> >
>
> What this does is ensures the persistence of the objects, by making them a
> static part of "self". Otherwise, they might appear for a fraction of a
> second, but be 'cleaned up' by automatic garbage collection.
slight elaboration: Tkinter maintains its own widget
tree, so you don't have to hang on to the widgets.
the "self.img" stuff is crucial, though:
http://www.python.org/doc/FAQ.html#4.69
</F>
More information about the Python-list
mailing list