I want to capture the time(in milliseconds) taken by a person to type a password, that is, from the first key press to the time the person presses Enter
button. To accomplish this, I have the following code:
import tkinter as tk
import time
class MyApp(object):
start=0.0
end=0.0
total_time=0.0
def __init__(self, master):
self.pass1 = tk.Entry(master,show="*")
self.pass1.bind('<Key>', self.callback1)
self.pass1.pack()
def callback1(self, event): # Called Only by first key press
self.start=time.time()*1000.0 # start variable must be modified ONLY by first key press
def callback2(self,event): # called by Enter Key press
self.end=time.time()*1000.0
self.total_time=self.start-self.end
print(self.totaltime)
root = tk.Tk()
app = MyApp(root)
root.mainloop()
The problem I am having is I am not able to bind callback1
and callback2
on pass1
. What I wanted was that when a person hit the first key of their password, start
is set to the current time and when the person press Enter
end
is initialized to the current time. I hope these two would give me an approximate of the time.
How can i modify the program above to accomplish what I want? Thanks.