[英]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. 我有具有渐变背景颜色的“
Canvas
面板,我想在其中添加一些带有png图像的按钮。 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. 我正在使用
create_image
方法,但它返回int并且无法将事件绑定到它。 How can i bind
event to Canvas
content? 如何
bind
事件bind
到Canvas
内容?
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
. 例如,我需要
bind
event bind
到bg
。 I can't bind
event to Canvas
because in future there will be more buttons which i need to click. 我无法
bind
事件bind
到Canvas
因为将来会有更多按钮需要单击。
Canvas does this with tags: Canvas使用标签来做到这一点:
tab.create_image(x, y, image=img, tags='item')
tab.tag_bind('item', '<Button-1>', click)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.