Skip to content
Related Articles

Related Articles

How to test Typing Speed using Python?

Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 09 Sep, 2021
Improve Article
Save Article

Prerequisites: Python GUI – tkinter

In this article, we will create a program test the typing speed of the user with a basic GUI application using Python language. Here the Python libraries like Tkinter and Timeit are used for the GUI and Calculation of time for speed testing respectively.  Also, the Random function is used to fetch the random words for the speed testing calculation. Following command is used to install the above-mentioned libraries:

pip install tkintertable
pip install pytest-timeit

Firstly, all the libraries are imported that are installed as mentioned above, and using the bottom-up approach the programming for testing the typing speed using python is created. 

Below is the implementation.


# importing all libraries
from tkinter import *
from timeit import default_timer as timer
import random
# creating window using gui
window = Tk()
# the size of the window is defined
x = 0
# defining the function for the test
def game():
    global x
    # loop for destroying the window
    # after on test
    if x == 0:
        x = x+1
    # defining function for results of test
    def check_result():
        if entry.get() == words[word]:
            # here start time is when the window
            # is opened and end time is when
            # window is destroyed
            end = timer()
            # we deduct the start time from end
            # time and calculate results using
            # timeit function
            print("Wrong Input")
    words = ['programming', 'coding', 'algorithm',
             'systems', 'python', 'software']
    # Give random words for testing the speed of user
    word = random.randint(0, (len(words)-1))
    # start timer using timeit function
    start = timer()
    windows = Tk()
    # use label method of tkinter for labeling in window
    x2 = Label(windows, text=words[word], font="times 20")
    # place of labeling in window, y=10)
    x3 = Label(windows, text="Start Typing", font="times 20"), y=50)
    entry = Entry(windows), y=55)
    # buttons to submit output and check results
    b2 = Button(windows, text="Done",
                command=check_result, width=12, bg='grey'), y=100)
    b3 = Button(windows, text="Try Again",
                command=game, width=12, bg='grey'), y=100)
x1 = Label(window, text="Lets start playing..", font="times 20"), y=50)
b1 = Button(window, text="Go", command=game, width=12, bg='grey'), y=100)
# calling window


In the above code, we first create the speed testing window using Tkinter. The function is defined for calculating and printing the correct output after the user input. A specific list of words is provided to the user to type and test the speed of typing. For that, we provide a list of words and generate them with the random function. 

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!