Tkinter demo to use countdown timer to check typing speed of user by using threading
User enters data ( type ) in a Text widget within a fixed time period.
Before adding data user has to click one Start button. This button will enable the data entry and the entery widget will be disabled once time is over.
One countdown timer will show the remaining time
Total number of chars entered in text widget will be displayed once the time period is over.
import tkinter as tk
from tkinter import BOTH, END, LEFT
import time
import threading
my_w = tk.Tk()
my_w.geometry("400x200")
duration=5 #duration of test
def my_start():
l2['text']=0 # remove previous data
t1.config(state='normal') # enable to enter text
t1.delete('1.0',END) # remove entered text at starting
for i in range(duration,-1,-1):
l1['text']=i # showing the time left
time.sleep(1)# one second delay
l2['text']=len(t1.get("1.0",'end-1c')) # total length
t1.config(state='disabled') # time over so disable
l1=tk.Label(my_w)
l1.place(relx=0.4,rely=0.1)
b1=tk.Button(my_w,text='Start',
command=lambda:threading.Thread(target=my_start).start())
#b1=tk.Button(my_w,text='Start',
# command=lambda:my_start())
b1.place(relx=0.2,rely=0.1)
t1=tk.Text(my_w,state='disabled',height=3,width=40)
t1.place(relx=0.1,rely=0.3) # user data entry
l2=tk.Label(my_w,text='')
l2.place(relx=0.1,rely=0.6) # display score
my_w.mainloop() # Keep the window open