What is the trick between these?

huey.y.jiang at gmail.com huey.y.jiang at gmail.com
Mon Aug 15 14:41:30 EDT 2016


Hi All,


I am trapped by these two funny things:

class MyClass(upClass):

   def start(self):
       ***do_menu_here****

       self.load_label_image()  # ---> this works
       self.load_canvas_image()  # ---> this does not work

   def load_label_image(self):
       img = PhotoImage(file="xx.gif")
       Label(self, image=img).pack(side=BOTTOM, expand=YES, fill=BOTH)
       return img

   def load_canvas_image(self):
       img = PhotoImage(file="xx.gif")       
       self.canvas = Canvas(self, width=500, height=300, bg='white')
       self.canvas.pack(expand=YES, fill=BOTH)
       self.canvas.create_image(50, 0, image=img, anchor=NW) 

if __name__ == '__main__':                      
        root = Tk()
        root.mainloop()

load_label_image() works. However, I cannot do BIND with it, because img has no method to do binding. So, I am trying load_canvas_image. Surprise, it does not work. These two defs are so similar, but Python complained that no attribute of load_canvas_image(). It is there, coexisting with load_label_image(). 

I cannot figure out what is wrong with it, can somebody tell me why? Thanks!



More information about the Python-list mailing list