faqts : Computers : Programming : Languages : Python : Tkinter : Events

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

10 of 11 people (91%) answered Yes
Recently 7 of 8 people (88%) answered Yes

Entry

Is there anyway to bind a canvas to key events?

Aug 21st, 2000 18:58
unknown unknown, Richard Chamberlain


from Tkinter import *
root=Tk()
canvas=Canvas(root)
canvas.pack()
def myDullEvent(event):
    print "Hallelujah! (is that how you spell it?)"
canvas.bind('<Key-a>',myDullEvent)
canvas.focus_set()
root.mainloop()
The only thing that is slightly tricky about it is that you need to make
sure the canvas has the focus.