What is the trick between these?
MRAB
python at mrabarnett.plus.com
Mon Aug 15 15:46:46 EDT 2016
On 2016-08-15 19:41, huey.y.jiang at gmail.com wrote:
> 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!
>
If you can't bind to the image itself, then bind to the label you put it
in instead.
More information about the Python-list
mailing list