
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
Python Tkinter Projects
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.