Python Project – Typing Speed Test

FREE Online Courses: Your Passport to Excellence - Start Now

Let’s build a python project to test the typing speed

In this article, We will create another python project with GUI. We will be using Tkinter to implement it. By the end of the project, you will be able to create more complex python projects with ease.

Project Prerequisites

This is a beginner-level python project. During the implementation of project, we will be needing tkinter, difflib, and few basic concepts of python

  • Python Basics
  • Tkinter

To install tkinter and difflib, please run the following commands in the terminal:

pip install tkinter
pip install difflib

Download Typing Speed Test Python Code

Please download the source code of python typing speed test: Typing Speed Test Python Code

Create Typing Test Python Files

Typing_test.py

from tkinter import *
import random
from timeit import default_timer 
import difflib
 
print("-----------ProjectGurukul - Python Typing Speed test------------")
 
root=Tk()
root.title('ProjectGurukul Typing test')
root.geometry("400x400")
 
entered=StringVar() 
 
greet = Label(root, font = ('arial', 30, 'bold'), text = "Welcome!")
greet.grid(row = 0,columnspan = 3)
 
words=['We are developing Python project', 'This is Windows Os', 'We are Hiring', 'Lets Play a game','Python is a programming language', 'We love Coding', 'This is an amazing Article', 'I am an Intern', 'Lets check the Output', 'we are Compiling this program' ]
word=random.choice(words)
 
def check():
    global entered
    global word
    global start
 
    string=f"{entered.get()}"
    end=  default_timer()
    time= round(end-start,2)
    print(time)
    speed=round(len(word.split())*60/time,2)
    print(speed)
 
    if string==word:
        Msg1 ="Time= " + str(time) + ' seconds'
        Msg2=" Accuracy= 100% "
        Msg3= " Speed= " + str(speed) + 'wpm' 
 
    else:
        accuracy=difflib.SequenceMatcher(None,word,string).ratio()
        accuracy=str(round(accuracy*100,2))
        Msg1 ="Time= "+ str(time) + ' seconds'
        Msg2=" Accuracy= " + accuracy + '%'
        Msg3= " Speed= " + str(speed) + ' wpm' #words per minute 
 
    
    label=Label(root, font = ('arial', 15, 'bold'), text = Msg1)
    label.grid(row = 7, columnspan = 3)
 
    label=Label(root, font = ('arial', 15, 'bold'), text = Msg2)
    label.grid(row = 8, columnspan = 3)
 
    label=Label(root, font = ('arial', 15, 'bold'), text = Msg3)
    label.grid(row = 9, columnspan = 3)
   
def play():
    global word
    global start
    global entered  
 
    label=Label(root, font = ('arial', 15), text = "Type here")
    label.grid(row = 5, column=1)
 
    entered=StringVar() 
    enter=Entry(root,textvariable=entered,font =('arial', 15),width=20)
    enter.grid(row=5,column=3)
 
    btn = Button(root, text = "Check",command=check,bg="DodgerBlue2",fg="white", font = ('arial', 10))
    btn.grid(row = 6,columnspan = 6)
 
 
label=Label(root, font = ('arial', 20, 'bold'), text = word)
label.grid(row = 3, columnspan = 3)
 
 
btn = Button(root, text = " Start typing",command=play,bg="DodgerBlue2",fg="white", font = ('arial', 10))
btn.grid(row = 4,columnspan = 6)
start= default_timer()
 
mainloop()

The sentences are selected randomly from the list ‘words’ and displayed on the screen. Along with randomly picking the sentences, we are initializing the start variable with default_timer().

Functions Used

Check():

We are using the default_timer function from the timeit module to calculate the time taken and then we are using a round function to round it to two decimal places.

We are calculating the speed using the formula (len(word) / time taken). It then checks the entered string with the current string and if both the strings do not match, it displays the time taken to type the given string, accuracy, and speed. To calculate accuracy we are using difflib’s SequenceMatcher function.

Play():

It asks the user to enter the given string using Entry and Label widgets of Tkinter. And after that, it calls the check function to display the result.

Python Typing Speed Test Output

typing speed test screenshot

test output

Summary

We have implemented the python typing speed test successfully. GUI application development in python is fun. Tkinter provides most of the functionalities as pre-built. We hope now you have a clear understanding of random(), default_timer() functions, and Tkinter.

Did you like this article? If Yes, please give ProjectGurukul 5 Stars on Google | Facebook

Leave a Reply

Your email address will not be published. Required fields are marked *