Before you go, check out these stories!

Hackernoon logoMake Your Own Typing Tutor App using Python! by@tarun-khare

Make Your Own Typing Tutor App using Python!

Author profile picture

@tarun-khareTarun Khare

Software developer, avid learner

When normal people want to learn typing, they use softwares like Typing master. But since we are programmers, we can use our knowledge to write our own typing tutor app. Python, as always will be best for this purpose as it is easy to understand and provides a lot of libraries for our specific purpose. So lets begin!

In order to check our typing speed and accuracy, we need to record keystrokes. To do this, we will be using a python library known as tkinter. Since tkinter is already inbuilt from Python 3.4 and above, so you won’t need to install it using pip.

How this app works?

First of all, we will take a dataset of many english letters. Then we will randomly present words from this dataset to the user. The user has to type these words. If he types a word successfully, he will get the next word. Also, the user will get a specific number of lives. The user will lose a life as soon as he types a letter wrong. If his lives finish, the game gets over. Also, a score is calculated based on the time taken by user to type a particular word, and number of letters typed correctly.

The dataset of English words used in this project can be found here. Download this file and store it in the same location where the python file is present. This file contains about 10,000 words of English. We will be randomly selecting a given number of words from this list. For score calculation, we increment score by one each time a letter is correctly pressed by user. Also a time limit is assigned to each word, which is a multiple of the word length. If the user types the word before the time limit, the leftover time gets added to the score.

The code.

import tkinter as tk
import random
from os import system, name
import time

def clear():
    if name == 'nt':
        _ = system('cls')
        _ = system('clear')

index = 0
list_index = 0
list = []
word_count = 10

f = open('words.txt', 'r')
for line in f:


list = list[:word_count]
print("Total words: ", len(list))
print("Word "+str(list_index+1)+" out of "+str(word_count)+": "+list[list_index])

start_time = time.time()
end_time = 0
time_multiplier = 2

lives = 3

score = 0

def keypress(event):
    global index
    global list_index
    global list
    global lives
    global score
    global start_time
    global end_time
    global time_multiplier

    word = list[list_index]

    if event.char == word[index]:
        index = index + 1
        score = score + 1
        print("Word " + str(list_index + 1) + " out of " + str(word_count) + ": " + list[list_index])
        print("wrong letter!")
        lives = lives - 1
        print("Lives left: ", lives)
        if lives == 0:
            print("Game Over!")
            print("Final Score: ", score)
    if index == len(word):
        index = 0
        list_index = list_index + 1
        end_time = time.time()
        time_taken = int(end_time - start_time)
        time_left = time_multiplier * len(word) - time_taken
        score = score + time_left
        print("time taken: " + str(time_taken) + " out of " + str(time_multiplier*len(word)) + " seconds.")
        print("Current score: ", score)
        start_time = end_time

    if list_index < len(list) and index == 0:
        print("Word " + str(list_index + 1) + " out of " + str(word_count) + ": " + list[list_index])

    elif list_index == len(list):
        print("Congratulations! you have beaten the game!")
        print("Final Score: ", score)

root = tk.Tk()
root.bind_all('', keypress)

Copy this code to a new python file and name it as The total number of words to be displayed in the game can be set using 

 variable. It is currently set at 100. The 
 variable controls the amount of time allotted to each word. Currently it is set at 2. This means for a word of length 5, the time limit is 5*2 = 10 seconds. The 
 variable defines the number of lives a player gets. A life gets over each time player incorrectly types a letter.

To run this code, open command prompt, change directory to the location where this python file is stored, and type: 


Note that after you run this code, command prompt will not remain as the active window. You don’t have to worry about it. Just start typing the letters of the word displayed. As you keep typing correctly, the score will update and next words will continue to appear. Also you won’t physically see the words being typed anywhere on screen. You just have to keep pressing the correct keys. Lives will be deducted whenever any incorrect key is pressed by you.

That’s It. Hope you liked the article. Comment in case of any doubts. Also check out my articles on medium and follow me on twitter. Also check out my other articles on this blog as well!


Join Hacker Noon

Create your free account to unlock your custom reading experience.