
import tkinter as tk
from tkinter import BOTH, END, LEFT
import time
import threading
import random
import string
my_w = tk.Tk()
my_w.geometry("400x200")
global Nos
Nos=0
duration=20 # time duration of test in seconds
word_size=4 # size of the random string generated
def my_start(): # start button is clicked
global Nos
l2['text']='' # 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): # change the duration of test
l1['text']=i # showing the time left
time.sleep(1)# one second delay
t1.config(state='disabled') # time over so disable
Nos=0 # Score set to 0 for next test
#random string generator
def id_generator(size=word_size, chars=string.ascii_lowercase):
return ''.join(random.choice(chars) for _ in range(size))
global str_ck # to store random string
str_ck=id_generator() # get random string
l1=tk.Label(my_w) # count down timmer
l1.place(relx=0.2,rely=0.1)
font1=('Time',18,'normal')
l3=tk.Label(my_w,text=str_ck,bg='yellow',font=font1)
l3.place(relx=0.3,rely=0.1) # show the random string
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.1,rely=0.1) # start button
t1=tk.Text(my_w,state='disabled',height=1,width=20,font=font1)
t1.place(relx=0.1,rely=0.3) # User entry box
l2=tk.Label(my_w,text='')
l2.place(relx=0.1,rely=0.5) # displaying score
def check_str(*args):
global Nos
global str_ck
if(t1.get("1.0",'end-1c')==str_ck):
Nos= Nos + word_size
t1.delete('1.0',END) # remove entered text
str_ck=id_generator()# one more randome string
l3['text']=str_ck # show the string
l2['text']="Completed " + str(Nos) + \
" in "+ str(duration) + " seconds"
t1.bind("<KeyRelease>",check_str) # User data entry Event handling
l_end=tk.Label(my_w,text='www.plus2net.com')
l_end.place(relx=0.3,rely=0.8)
my_w.mainloop() # Keep the window open
Python Tkinter Projects
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.