| | |
KeyPress event with holding down the key
![]() |
Ah, thanks to both of you. Yup, as far as I can tell, it's interpreting the continuous press as you said, as a repeated keypress/keyrelease event pair. My guess is that it's to do with the Mac or possibly the version of Tkinter I'm using.
I'm looking forward to what you find out, Jeff. Could you please post it here or send me a private message when you hear?
Cheers,
Aot
I'm looking forward to what you find out, Jeff. Could you please post it here or send me a private message when you hear?
Cheers,
Aot
You will have to sit there with a stopwatch, but this could do the timing for you ...
python Syntax (Toggle Plain Text)
# count how many times the keyboard is scanned on # one continuous keypress of character 'a' import Tkinter as tk class MyFrame(tk.Frame): def __init__(self, master): tk.Frame.__init__(self, master) # method call counter self.counter_press = 0 self.pack() root.bind_all('<a>', self.key_press) def key_press(self, event): self.counter_press += 1 # show result in title root.title(str(self.counter_press)) root = tk.Tk() root.geometry("400x30+0+0") app1 = MyFrame(root) root.mainloop()
May 'the Google' be with you!
•
•
Join Date: Nov 2007
Posts: 1
Reputation:
Solved Threads: 0
I was having the same problem, the ideas here brought me to the solution, using the after_idle methode:
python Syntax (Toggle Plain Text)
from Tkinter import * class MyFrame(Frame): def __init__(self, master): tk.Frame.__init__(self, master) # method call counter self.pack() self.afterId = None root.bind('<KeyPress-a>', self.key_press) root.bind('<KeyRelease-a>', self.key_release) def key_press(self, event): if self.afterId != None: self.after_cancel( self.afterId ) self.afterId = None else: print 'key pressed %s' % event.time def key_release(self, event): self.afterId = self.after_idle( self.process_release, event ) def process_release(self, event): print 'key release %s' % event.time self.afterId = None root = Tk() root.geometry("400x30+0+0") app1 = MyFrame(root) root.mainloop()
Last edited by Quarks; Nov 4th, 2007 at 6:09 pm.
![]() |
Other Threads in the Python Forum
- Previous Thread: noob: What and when you would use Decimal vs Float Type
- Next Thread: assign the values to each members of a large list of class objects
| Thread Tools | Search this Thread |
alarm app assignment avogadro beginner bluetooth character cipher cmd coordinates customdialog cx-freeze data decimals development dictionary directory dynamic error exe feet file float format function generator getvalue gnu graphics halp handling homework http ideas images import input ip itunes java keycontrol leftmouse line linux list lists loop maintain maze millimeter module mouse number numbers output parsing path port prime programming push py2exe pygame pymailer python queue random recursion schedule screensaverloopinactive script scrolledtext slicenotation split sqlite ssh string strings sudokusolver text threading time tlapse tuple tutorial ubuntu unicode url urllib urllib2 variable variables ventrilo vigenere web webservice wikipedia wxpython xlib xlwt






