typing speed test in python using gui

introduction

Typing has become an essential skill in today’s digital era, whether for programming, professional communication, data entry, or online exams. The ability to type quickly and accurately can significantly enhance productivity and reduce time spent on written tasks. To measure and improve this skill, a Typing Speed Test in python tool is a simple yet effective solution.

This project presents a Typing Speed Test in python application with a Graphical User Interface (GUI) using Python’s built-in Tkinter library. The GUI allows users to interactively practice their typing, track their speed in Words Per Minute (WPM), and get real-time feedback. The project is implemented entirely within a Jupyter Notebook, making it accessible and easy to run for learners, educators, and developers.

The test begins by showing the user a randomly selected sentence. Once the user starts typing, the program captures the start time. After the user finishes typing and clicks the “Check Speed” button, it calculates the total time taken, compares the typed input with the target sentence, and then computes and displays the typing speed in words per minute. If the typed text matches exactly, it acknowledges correctness; otherwise, it provides feedback on accuracy while still reporting the WPM.

This typing speed test not only helps users measure their current typing performance but also encourages them to practice and gradually improve both their speed and accuracy.

Project Objectives:

  • Build an interactive typing test application using Tkinter in Python.

  • Display random sentences for users to type.

  • Measure the typing duration and calculate WPM.

  • Provide real-time feedback on performance.

  • Enable typing practice in a structured way.

 Learning Outcomes:

  • Learn how to create a GUI using Tkinter in Python.

  • Understand how to track time-based events using the time module.

  • Gain hands-on experience with event-driven programming.

  • Learn how to compare strings, calculate word count, and display results dynamically.

  • Use randomization and conditional logic in GUI applications.

Target Users:

  • Students and beginners learning to type efficiently.

  • Python learners exploring Tkinter and GUI design.

  • Teachers or trainers building digital typing labs.

  • Anyone who wants to track and improve their typing speed.

steps to create typing speed test in python

Step 1: Import Required Libraries

Begin by importing the necessary libraries. Tkinter is used for GUI creation, random for selecting test sentences, and time to measure typing speed.

import tkinter as tk
import random
import time

Step 2: Create a List of Test Sentences

Prepare a list of sentences that users will type during the test.

sentences = [
    "Typing speed is measured in words per minute.",
    "Python is a versatile programming language.",
    "Practice makes a person perfect in typing.",
    "Tkinter makes GUI development simple and fast.",
    "Artificial Intelligence is shaping the future."
]

Step 3: Define Global Variables

Set up variables to track the selected sentence and start time.

start_time = 0
selected_sentence = ""

Step 4: Define the Function to Start the Typing Test

Create a function that selects a random sentence, displays it in the GUI, and records the start time.

def start_test():
    global start_time, selected_sentence
    selected_sentence = random.choice(sentences)
    sentence_label.config(text=selected_sentence)
    entry.delete(0, tk.END)
    result_label.config(text="")
    start_time = time.time()

Step 5: Define the Function to Check Typing Speed

Create another function that calculates the time taken, counts words, and determines WPM. It compares the user’s input with the original sentence.

def check_speed():
    end_time = time.time()
    typed_text = entry.get()
    time_taken = end_time - start_time

    if typed_text.strip() == "":
        result_label.config(text="Please type something!")
        return

    word_count = len(typed_text.strip().split())
    wpm = round((word_count / time_taken) * 60)

    if typed_text.strip() == selected_sentence:
        result = f"Correct! Your typing speed is {wpm} WPM."
    else:
        result = f"Incorrect! You typed {wpm} WPM."

    result_label.config(text=result)

Step 6: Create the Main GUI Window

Initialize the Tkinter window, set the title, size, and background color.

root = tk.Tk()
root.title("Typing Speed Test")
root.geometry("600x300")
root.config(bg="white")

Step 7: Add GUI Widgets

Add labels, entry box, and buttons to interact with the user.

instruction = tk.Label(root, text="Click 'Start Test' and type the sentence as fast as you can.", bg="white")
instruction.pack(pady=10)

sentence_label = tk.Label(root, text="", font=("Arial", 14), wraplength=500, bg="white")
sentence_label.pack(pady=10)

entry = tk.Entry(root, font=("Arial", 12), width=70)
entry.pack(pady=10)

start_btn = tk.Button(root, text="Start Test", command=start_test, bg="#4CAF50", fg="white")
start_btn.pack(pady=5)

check_btn = tk.Button(root, text="Check Speed", command=check_speed, bg="#2196F3", fg="white")
check_btn.pack(pady=5)

result_label = tk.Label(root, text="", font=("Arial", 12), fg="black", bg="white")
result_label.pack(pady=10)

Step 8: Run the Application

Start the Tkinter main loop to launch the GUI.

root.mainloop()

code explanation

🔹 Import Libraries

import tkinter as tk
import random
import time
  • tkinter: for GUI components

  • random: to randomly select a sentence

  • time: to measure how long the user takes to type

🔹 Create Sentence List

sentences = [...]
  • A list of sample sentences for typing practice.

  • The app randomly picks one for each test.

🔹 Initialize Global Variables

start_time = 0
selected_sentence = ""
  • start_time: stores the time when user starts typing

  • selected_sentence: holds the sentence shown to the user

🔹 Start Typing Test Function

def start_test():
    global start_time, selected_sentence
  • Makes variables accessible inside the function.

    selected_sentence = random.choice(sentences)
    sentence_label.config(text=selected_sentence)
  • Chooses a random sentence and displays it.

    entry.delete(0, tk.END)
    result_label.config(text="")
  • Clears the entry box and result label.

    start_time = time.time()
  • Records the current time as start time.

🔹 Check Typing Speed Function

def check_speed():
    end_time = time.time()
    typed_text = entry.get()
  • Gets current time and what the user typed.

    time_taken = end_time - start_time
  • Calculates duration of typing in seconds.

    if typed_text.strip() == "":
        result_label.config(text="Please type something!")
        return
  • If user hasn’t typed anything, display a warning.

    word_count = len(typed_text.strip().split())
    wpm = round((word_count / time_taken) * 60)
  • Counts words and calculates words per minute (WPM) using:

    WPM=(wordsseconds)×60\text{WPM} = \left(\frac{\text{words}}{\text{seconds}}\right) \times 60
    if typed_text.strip() == selected_sentence:
        result = f"Correct! Your typing speed is {wpm} WPM."
    else:
        result = f"Incorrect! You typed {wpm} WPM."
  • Compares typed input to original sentence.

  • Displays appropriate feedback.

    result_label.config(text=result)
  • Shows result on GUI.

🔹 Create GUI Window

root = tk.Tk()
root.title("Typing Speed Test")
root.geometry("600x300")
root.config(bg="white")
  • Initializes the main window.

  • Sets title, size, and background color.

🔹 Add Instruction Label

instruction = tk.Label(...)
instruction.pack(pady=10)
  • Informs the user what to do.

🔹 Sentence Display Label

sentence_label = tk.Label(...)
sentence_label.pack(pady=10)
  • Will display the randomly selected sentence.

🔹 Text Entry Widget

entry = tk.Entry(...)
entry.pack(pady=10)
  • Where the user types the sentence.

🔹 Start Button

start_btn = tk.Button(..., command=start_test, ...)
start_btn.pack(pady=5)
  • When clicked, starts the typing test.

🔹 Check Button

check_btn = tk.Button(..., command=check_speed, ...)
check_btn.pack(pady=5)
  • When clicked, ends the test and calculates WPM.

🔹 Result Display Label

result_label = tk.Label(...)
result_label.pack(pady=10)
  • Shows typing result after checking.

🔹 Start GUI Event Loop

root.mainloop()
  • Keeps the window open and interactive.

 Summary

ComponentPurpose
start_test()Displays sentence, records start time
check_speed()Calculates WPM and displays result
tk.EntryTyping input field
tk.LabelShows sentence and result
tk.ButtonControls actions (Start / Check)
time.time()Tracks how long user takes to type

 

source code

				
					import tkinter as tk
import random
import time

# Sample text list
sentences = [
    "Typing speed is measured in words per minute.",
    "Python is a versatile programming language.",
    "Practice makes a person perfect in typing.",
    "Tkinter makes GUI development simple and fast.",
    "Artificial Intelligence is shaping the future."
]

# Global variables
start_time = 0
selected_sentence = ""

# Function to start the test
def start_test():
    global start_time, selected_sentence
    selected_sentence = random.choice(sentences)
    sentence_label.config(text=selected_sentence)
    entry.delete(0, tk.END)
    result_label.config(text="")
    start_time = time.time()

# Function to check typing speed
def check_speed():
    end_time = time.time()
    typed_text = entry.get()
    time_taken = end_time - start_time

    if typed_text.strip() == "":
        result_label.config(text="Please type something!")
        return

    word_count = len(typed_text.strip().split())
    wpm = round((word_count / time_taken) * 60)

    if typed_text.strip() == selected_sentence:
        result = f"Correct! Your typing speed is {wpm} WPM."
    else:
        result = f"Incorrect! You typed {wpm} WPM."

    result_label.config(text=result)

# Create main window
root = tk.Tk()
root.title("Typing Speed Test")
root.geometry("600x300")
root.config(bg="white")

# GUI Components
instruction = tk.Label(root, text="Click 'Start Test' and type the sentence as fast as you can.", bg="white")
instruction.pack(pady=10)

sentence_label = tk.Label(root, text="", font=("Arial", 14), wraplength=500, bg="white")
sentence_label.pack(pady=10)

entry = tk.Entry(root, font=("Arial", 12), width=70)
entry.pack(pady=10)

start_btn = tk.Button(root, text="Start Test", command=start_test, bg="#4CAF50", fg="white")
start_btn.pack(pady=5)

check_btn = tk.Button(root, text="Check Speed", command=check_speed, bg="#2196F3", fg="white")
check_btn.pack(pady=5)

result_label = tk.Label(root, text="", font=("Arial", 12), fg="black", bg="white")
result_label.pack(pady=10)

root.mainloop()

				
			

output

More java Pojects
Get Huge Discounts