简体   繁体   中英

How to bind event for Canvas content?

I have Canvas panel with gradient background color, and i want to add there some buttons with png images. Using canvas is only one solution to make good transparent textured buttons. I am using create_image method but it returns int and i cant bind event to it. How can i bind event to Canvas content?

self.tab = tk.Canvas(width=xc,height=yc,bd=0, highlightthickness=0)
self.tab.pack(side=tk.BOTTOM, fill=tk.X)
bg = self.tab.create_image(xc/2, yc/2, image=self.toolbar_image)

For example i need to bind event to bg . I can't bind event to Canvas because in future there will be more buttons which i need to click.

Canvas does this with tags:

tab.create_image(x, y, image=img, tags='item')
tab.tag_bind('item', '<Button-1>', click)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM