How to test Typing Speed using Python? - GeeksforGeeks

09 Sep, 2021
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.
Python3
# importing all librariesfrom tkinter import *from timeit import default_timer as timerimport random # creating window using guiwindow = Tk() # the size of the window is definedwindow.geometry("450x200") x = 0 # defining the function for the testdef game():    global x     # loop for destroying the window    # after on test    if x == 0:        window.destroy()        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(end-start)        else:            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()    windows.geometry("450x200")     # use label method of tkinter for labeling in window    x2 = Label(windows, text=words[word], font="times 20")     # place of labeling in window    x2.place(x=150, y=10)    x3 = Label(windows, text="Start Typing", font="times 20")    x3.place(x=10, y=50)     entry = Entry(windows)    entry.place(x=280, y=55)     # buttons to submit output and check results    b2 = Button(windows, text="Done",                command=check_result, width=12, bg='grey')    b2.place(x=150, y=100)     b3 = Button(windows, text="Try Again",                command=game, width=12, bg='grey')    b3.place(x=250, y=100)    windows.mainloop()  x1 = Label(window, text="Lets start playing..", font="times 20")x1.place(x=10, y=50) b1 = Button(window, text="Go", command=game, width=12, bg='grey')b1.place(x=150, y=100) # calling windowwindow.mainloop()
Output:
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. 
simranarora5sos
Python Tkinter-exercises
Python-projects
Python-tkinter
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Read a file line by line in Python
How to Install PIP on Windows ?
Enumerate() in Python
Different ways to create Pandas Dataframe
Iterate over a list in Python
Python String | replace()
*args and **kwargs in Python
Reading and Writing to text files in Python
Create a Pandas DataFrame from Lists