TK and PhotoImage: Problem getting image to display

Kevin Cazabon kcazabon at home.com
Thu Feb 24 01:26:30 EST 2000


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.

Kevin Cazabon.

"Timothy Grant" <tjg at avalongroup.net> wrote in message
news:38B4774E.9BE01006 at exceptionalminds.com...
> Hi all,
>
> Just started playing with some of the image aspects of Tkinter, and I
> immediately ran into a roadblock. I found a similar problem in the
> archives, but I can't get the resolution to work for me. Given the code
> below, I successfully create the canvas, but can't for the life of me
> figure out how to get my gif to display inside the canvas.
>
> All suggestions greatfully accepted...
>
>
> from Tkinter import *
>
> class Quoter:
>     def __init__(self, master):
>         qFrame = Frame(master)
>         qFrame.pack(side=TOP)
>
>         #qCompanyLogoCanvas =  Canvas(qFrame, width=275, height=50)
>         #qCompanyLogoCanvas.pack(side=LEFT)
>
>         img = PhotoImage(file='amos3.gif')
>         qAMOSLogoCanvas = Canvas(qFrame, width=300, height=300)
>         qAMOSLogoCanvas.create_image(0, 0, anchor=NW, image=img)
>         qAMOSLogoCanvas.pack()
>
> if __name__ == '__main__':
>     root = Tk()
>     Pmw.initialise(root)
>
>     root.title('AMOSoft Quoting')
>
>     quoter = Quoter(root)
>
>     root.mainloop()
>
>
>
> --
> Stand Fast,
>     tjg.
>
> Chief Technology Officer              tjg at exceptionalminds.com
> Red Hat Certified Engineer            www.exceptionalminds.com
> Avalon Technology Group, Inc.                   (503) 246-3630
> >>>>>>>>>>>>Linux...Because rebooting isn't normal<<<<<<<<<<<<
>





More information about the Python-list mailing list