TK and PhotoImage: Problem getting image to display

Kevin Cazabon kcazabon at home.com
Fri Feb 25 00:05:36 EST 2000


Yes, I completely agree... however I prefer to still use self.frame = ...
and so forth, because it makes configuring them afterwards much easier.

It's simpler to call self.frame.config(option=whatever) than to try to track
the instance of the widget itself.

Kevin Cazabon.


"Fredrik Lundh" <effbot at telia.com> wrote in message
news:x4ct4.802$mYj.191054848 at newsa.telia.net...
> 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