How to test Typing Speed using Python?
Difficulty Level : Basic
Last Updated : 05 Sep, 2020
Prerequisites: Python GUI – tkinter
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.
from tkinter import *
from timeit import default_timer as timer
import random
window = Tk()
window.geometry("450x200")
x = 0
def game():
global x
if x == 0:
window.destroy()
x = x+1
def check_result():
if entry.get() == words[word]:
end = timer()
print(end-start)
else:
print("Wrong Input")
words = ['programming', 'coding', 'algorithm',
'systems', 'python', 'software']
word = random.randint(0, (len(words)-1))
start = timer()
windows = Tk()
windows.geometry("450x200")
x2 = Label(windows, text=words[word], font="times 20")
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)
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)
window.mainloop()
Output:
Video Player
00:00
00:15
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.