ImageTk.Photoimage not displayed

harryos oswald.harry at gmail.com
Thu Aug 28 15:07:42 EDT 2008


hi
i am trying to display an image on a canvas in a gui made with Tkinter
widgets


class PhotoDisplay:
    def __init__(self,parent):
        self.mainframe = Frame(parent,background="grey")
        .....
        #added a subframe to hold canvas and button
        ....
       self.canvFrame=Frame(self.mainframe,...)
       ....
       self.mycanvas=Canvas(self.canvFrame,...)
       ...

    def okbuttonClick(self):
        self.mycanvas.delete(ALL)
        myimagename=...#get an imagefilename from somewhere..
        self.showSelectedImage(myimagename)

    def showSelectedImage(self,imageName):
        myimg=ImageTk.PhotoImage(file=imageName)
        imgtag=self.mycanvas.create_image(70,100,image=myimg)
        self.mycanvas.update_idletasks()


when i click the button ,the image is displayed for a fraction of a
second on the canvas and disappears.I couldn't figure out why this is
happening.I am quite new to Tkinter and still going  thru Fredrik
Lundh's intro to tkinter..can someone tell me if i am doing sthing
wrong here?
thanks in advance
harry



More information about the Python-list mailing list