Python event binding with tkinter Python event binding with tkinter tkinter tkinter

Python event binding with tkinter


It doesn't execute the callback function because the focus of the program is on the Tk element. If you replace that line with root.bind("a", callback), it will work as you expect.

The problem is that the canvas element doesn't receive the focus when you click on it like other widgets as Entry, so it will only respond to keydown events if you call first canvas.focus_set().