Using Tkinter and what you have learnt about building GUI applications with Python, build a desktop app that assesses your typing speed. Give the user some sample text and detect how many words they can type per minute.

The average typing speed is 40 words per minute. But with practice, you can speed up to 100 words per minute.

You can try out a web version here:

https://typing-speed-test.aoeu.eu/

If you have more time, you can build your typing speed test into a typing trainer, with high scores and more text samples. You can design your program any way you want.

GUI View:

Untitled

Solution:

import tkinter as tk
from tkinter import Text
import requests

class Question:
    def get_quote(self):
        response = requests.get("<https://api.kanye.rest/>")
        print(response.status_code)
        data = response.json()
        return data["quote"]
        #print(data["quote"])

class TypingSpeedApp:
        
    def __init__(self, root, sample_text="test"):
        self.root = root
        self.root.title("Typing Speed Assessment App")

        # Sample text for typing
        #self.sample_text = "The quick brown fox jumps over the lazy dog."
        self.sample_text = sample_text
        self.sample_words = self.sample_text.split()

        # Variables to track typing progress
        self.current_word_index = 0
        self.correct_words = 0
        self.start_time = None

        # Question Text Area
        self.question_text = Text(root, wrap=tk.WORD, height=4, width=50)
        self.question_text.insert(tk.END, self.sample_text)
        self.question_text.config(state=tk.DISABLED)
        self.question_text.pack(pady=10)

        # Typing Area
        self.typing_area = Text(root, wrap=tk.WORD, height=4, width=50)
        self.typing_area.pack(pady=10)
        self.typing_area.bind('<Key>', self.check_typing)

        # Reset Button
        self.reset_button = tk.Button(root, text="Reset", command=self.reset_game)
        self.reset_button.pack(pady=10)

    def check_typing(self, event):
        typed_word = self.typing_area.get("1.0", tk.END).split()[-1]
        expected_word = self.sample_words[self.current_word_index]

        if typed_word == expected_word:
            self.correct_words += 1
            self.current_word_index += 1
            self.update_highlight()

            if self.current_word_index == len(self.sample_words):
                self.finish_typing()

    def update_highlight(self):
        self.question_text.tag_remove("highlight", "1.0", tk.END)
        end_index = f"1.{len(' '.join(self.sample_words[:self.current_word_index+1]))}"
        self.question_text.tag_add("highlight", "1.0", end_index)
        self.question_text.tag_configure("highlight", background="green")

    def finish_typing(self):
        elapsed_time = time.time() - self.start_time if self.start_time else 0
        words_per_minute = int(self.correct_words / elapsed_time * 60)

        result_text = f"Typing Speed: {words_per_minute} words per minute\\n"
        result_text += "Average typing speed is 40 words per minute.\\n"
        result_text += "With practice, you can speed up to 100 words per minute."

        result_label = tk.Label(self.root, text=result_text, font=("Helvetica", 12))
        result_label.pack(pady=10)

        self.typing_area.config(state=tk.DISABLED)
        self.typing_area.unbind('<Key>')

    def reset_game(self):
        self.current_word_index = 0
        self.correct_words = 0
        self.start_time = time.time()

        self.typing_area.config(state=tk.NORMAL)
        self.typing_area.delete("1.0", tk.END)

        self.question_text.tag_remove("highlight", "1.0", tk.END)
        self.question_text.tag_configure("highlight", background="white")

        result_label = tk.Label(self.root, text="", font=("Helvetica", 12))
        result_label.pack_forget()

        self.typing_area.bind('<Key>', self.check_typing)
        question = Question()
    
        # Question Text Area
        # Reset the question text area highlighting
        self.question_text.config(state=tk.NORMAL)
        self.question_text.delete("1.0", tk.END)
        self.question_text.insert(tk.END, question.get_quote())
        self.question_text.config(state=tk.DISABLED)

    def run(self):
        self.start_time = time.time()
        self.root.mainloop()

if __name__ == "__main__":
    import time

    question = Question()

    root = tk.Tk()
    app = TypingSpeedApp(root,question.get_quote())
    app.run()