Python: Keyboard input without repeat delay Python: Keyboard input without repeat delay tkinter tkinter

Python: Keyboard input without repeat delay


Make a recursion loop for while it is pressed. Or that's how I do it, at least.

moving = Falsedef move():  global moving  moving = Truedef stop_moving():  global moving  moving = Falsedef myloop():  global moving  if moving == True:    canvas.move(ball, 0, 3)  root.after(1, myloop)root.bind('<space>', lambda e: move())root.bind('<KeyRelease-space>', lambda e: stop_moving())

just make sure you call your loop once before root.mainloop()

#like thisroot.after(1, myloop)root.mainloop()