Keyup handler in Tkinter? Keyup handler in Tkinter? tkinter tkinter

Keyup handler in Tkinter?


You can define events prefixed with KeyRelease, such as <KeyRelease-a>. For example:

canvas.bind("<KeyRelease-a>", do_something)

Note: you need to remove your while loop. You should never create an infinite loop inside a GUI program, and you definitely don't want to be creating a frame every iteration -- you'll end up with thousands of frames in only a second or two!

You already have an infinite loop running, mainloop. If you want to do animation, use after to run a function every few milliseconds. For example, the following will cause a ball to move 10 pixels every 10th of a second. Of course, you'll want to handle the case where it moves off screen or bounces or whatever. The point is, you write a function that draws one frame of animation, and then have that function be called periodically.

def animate():    canvas.move("ball", 10, 0)    canvas.after(100, animate)