Bind action to canvas : Canvas « GUI Tk « Python






Bind action to canvas

Bind action to canvas


from Tkinter import * 

def onCanvasClick(event):                  
    print 'Got canvas click', event.x, event.y, event.widget

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

canv.bind('<Double-1>', onCanvasClick)                  
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 mouse click action to the object on a canvasBind mouse click action to the object on a canvas
6.Use mouse to draw a shape on canvasUse mouse to draw a shape on canvas
7.Image canvasImage canvas