Typing Speed Test

Tkinter based app which tests your typing speed

Posted by Kossanovic on February 27, 2023

Typing Speed Test with Python and Tkinter

The provided code is a speed typing test that allows users to test their typing skills. The program provides the user with a set of words that they need to type within a certain time limit. The user's typing speed is measured in terms of the number of words they can type in a minute (WPM) and the number of characters they can type in a minute (CPM). The program also tracks the user's mistakes and provides them with feedback on their performance.

The program is written using the Tkinter library for the GUI. The GUI is built using frames and labels to display the text and statistics. The program loads a set of words from the 'words' module and displays them in a disabled Text widget. The user can type the words in an Entry widget, and their input is checked against the correct word using the 'check_if_word_is_correct' method. If the word is correct, it is highlighted in green, and the user's correct count is incremented. If the word is incorrect, it is highlighted in red, and the user's mistake count is incremented.

The program includes a countdown timer that starts when the user makes their first input. When the timer reaches zero, the user's input is disabled, and the program displays the final statistics, including the user's correct and incorrect word counts, and their CPM.

The program also includes a 'Restart' button that allows the user to restart the test. The 'restart_program'.

from tkinter import Tk, Frame, Text, Entry, Label, Button
from words import Words

class Gui():
    def __init__(self):
        self.root = Tk()
        self.root.geometry("1000x600")
        self.root.config()
        self.gui_frames()
        self.variables()
[...]

    def move_cursor(self, event=None):
        """ When countdown timer is running. Using word from user input.
        Moves cursor on the beginning of current word, starting with 0.
        Adds word count. Loads current_word from list of words loaded
        from dictionary of words. Scrolls text with users typing
        progress.
        """
        if self.countdown_is_on:
            self.get_word_from_input()
            self.textbox_cursor_placement += len(self.current_word)+1
            self.word_count += 1
            self.current_word = self.loaded_words_from_dict[self.word_count]
            self.text.see(
                f"{1.0} + {self.textbox_cursor_placement + 50} chars")
            print(f"{self.current_word} : {self.current_word_range}")
            self.highlight_current_word()
            self.config_wpm_label()
            self.config_cpm_label()
[...]
    def start_timer(self):
        """ If timer is not running it can be run """
        if not self.countdown_is_on:
            self.countdown(60)
        self.countdown_is_on = True
[...]
window = Gui()
window.enter_word()
window.highlight_current_word()
window.timer_bind()
window.root.mainloop()