0% found this document useful (0 votes)
3 views7 pages

Program Code

This document contains a Python program that implements a typing speed tester using the Tkinter library. It provides a user interface for users to practice typing with various prompts, calculates their typing speed in words per minute (WPM), and tracks accuracy. The program includes features such as a welcome screen, real-time feedback on typing accuracy, and the ability to retry the test.

Uploaded by

chetanmahale523
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

Program Code

This document contains a Python program that implements a typing speed tester using the Tkinter library. It provides a user interface for users to practice typing with various prompts, calculates their typing speed in words per minute (WPM), and tracks accuracy. The program includes features such as a welcome screen, real-time feedback on typing accuracy, and the ability to retry the test.

Uploaded by

chetanmahale523
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

PROGRAM CODE

import tkinter as tk
import time
import random

PROMPTS = [
"The quick brown fox jumps over the lazy dog. This
sentence contains every letter in the English alphabet,
making it a great practice tool.",
"Typing fast requires a lot of practice and patience. The
more you type, the better you become at both speed and
accuracy.",
"Python programming is fun and powerful. With practice,
you can build applications, automate tasks, and even
develop artificial intelligence models.",
"Speed and accuracy are both important in typing. It is
not just about typing fast, but also about making as few
mistakes as possible.",
"A good typist focuses on precision first, and then builds
speed over time. Consistent practice with challenging
texts helps improve performance."
]
class TypingTester:
def __init__(self, root):
self.root = root
self.root.title("Typing Speed Tester")
self.root.geometry("800x500")

self.show_welcome_screen()

def show_welcome_screen(self):

self.clear_screen()

self.root.configure(bg="#E3F2FD") # Light blue


background

self.label_welcome = tk.Label(
self.root, text="Welcome to Typing Speed Tester",
font=("Arial", 28, "bold"),
bg="#E3F2FD", fg="#0D47A1"
)
self.label_welcome.pack(pady=20)
self.label_subtitle = tk.Label(
self.root, text="Improve your typing speed and
accuracy with our test!",
font=("Arial", 16),
bg="#E3F2FD", fg="#1565C0"
)
self.label_subtitle.pack(pady=10)

self.button_start = tk.Button(
self.root, text="Start Typing Test",
command=self.start_typing_test,
font=("Arial", 16, "bold"),
bg="#64B5F6", fg="white",
padx=15, pady=10,
relief="raised", bd=3
)
self.button_start.pack(pady=20)

self.label_footer = tk.Label(
self.root, text="Get ready to type fast and
accurately!",
font=("Arial", 14, "italic"),
bg="#E3F2FD", fg="#1E88E5"
)
self.label_footer.pack(pady=10)

def start_typing_test(self):
"""Starts the typing test after clicking start."""
self.reset_test()

self.label_prompt = tk.Label(self.root,
text=self.prompt_text, font=("Arial", 14), wraplength=750,
justify="left")
self.label_prompt.pack(pady=10)

self.entry_text = tk.Text(self.root, height=5, width=90,


font=("Arial", 14), wrap="word")
self.entry_text.pack(pady=10)
self.entry_text.bind("<KeyPress>", self.start_timer)
self.entry_text.bind("<KeyRelease>",
self.check_typing)

self.button_submit = tk.Button(self.root,
text="Submit", command=self.calculate_results,
font=("Arial", 12))
self.button_submit.pack(pady=5)

self.button_retry = tk.Button(self.root, text="Retry",


command=self.reset_test, font=("Arial", 12))
self.button_retry.pack(pady=5)

self.label_result = tk.Label(self.root, text="",


font=("Arial", 12))
self.label_result.pack(pady=10)

def reset_test(self):
"""Resets the typing test with a new prompt."""
self.clear_screen()
self.prompt_text = random.choice(PROMPTS)
self.start_time = None

def start_timer(self, event):


"""Starts the timer when the user types the first
character."""
if self.start_time is None:
self.start_time = time.time()

def check_typing(self, event):


"""Checks typed text and provides real-time color
feedback."""
typed_text = self.entry_text.get("1.0", tk.END).strip()
correct_text = self.prompt_text[:len(typed_text)]

if typed_text == correct_text:
self.entry_text.config(fg="green")
else:
self.entry_text.config(fg="red")

def calculate_results(self):
"""Calculates WPM and accuracy when the user
submits the text."""
if self.start_time is None:
self.label_result.config(text="Start typing first!",
fg="red")
return

end_time = time.time()
elapsed_time = end_time - self.start_time
typed_text = self.entry_text.get("1.0", tk.END).strip()

num_words = len(typed_text.split())
wpm = (num_words / elapsed_time) * 60 if
elapsed_time > 0 else 0

correct_chars = sum(1 for i, char in


enumerate(typed_text) if i < len(self.prompt_text) and char
== self.prompt_text[i])
accuracy = (correct_chars / len(self.prompt_text)) *
100

self.label_result.config(text=f"WPM:
{wpm:.2f}\nAccuracy: {accuracy:.2f}%\nTime:
{elapsed_time:.2f} sec", fg="blue")

def clear_screen(self):
"""Clears all widgets from the window."""
for widget in self.root.winfo_children():
widget.destroy()

if __name__ == "__main__":
root = tk.Tk()
app = TypingTester(root)
root.mainloop()

You might also like