Bind mouse click action to the object on a canvas : Canvas « GUI Tk « Python






Bind mouse click action to the object on a canvas

Bind mouse click action to the object on a canvas

from Tkinter import * 

def onObjectClick(event):                  
    print 'Clicked', event.x, event.y, event.widget,
    print event.widget.find_closest(event.x, event.y)   

root = Tk()
canv = Canvas(root, width=100, height=100)
obj1 = canv.create_text(50, 30, text='Click me one')
obj2 = canv.create_text(50, 70, text='Click me two')

canv.tag_bind(obj1, '<Double-1>', onObjectClick)        
canv.tag_bind(obj2, '<Double-1>', onObjectClick)        
canv.pack()
root.mainloop()


           
       








Related examples in the same category

1.Canvas: Simple plotCanvas: Simple plot
2.Bound Scale action with a canvasBound Scale action with a canvas
3.Canvas inside a frameCanvas inside a frame
4.Use canvas to draw line, oval, rectangle, bitmap and arc
5.Bind action to canvasBind action to canvas
6.Use mouse to draw a shape on canvasUse mouse to draw a shape on canvas
7.Image canvasImage canvas