This simple application almost does what I want:
import Tkinter as Tk
def hello(x):
print "Hello"
root = Tk.Tk()
root.bind("<Up>", hello)
root.mainloop()
I mash down the up arrow, it prints “Hello” over and over. However, there is a delay before this repetition begins, and the repetition rate is slower than I want. How can I set this repeat delay to zero? How can I control the repeat interval?
I know that other Tkinter widgets have configuration options for ‘repeatdelay’ and ‘repeatinterval’, but I can’t seem to find one for a Tkinter root window.
(I’m looking in your direction, Bryan Oakley)
This is not something configurable in Tk — Tk has no control over how fast the keyboard driver sends repeated key events.
What you can do instead is have a binding on the button press and button release to set and then unset a flag. Then, you can write a function that does whatever you want it to do, then check the flag and call itself again after whatever delay you want.
The function would look something like this:
To do it right requires a little bit more logic, but that’s the general idea.