Typing Test Python Project

Free Python courses with 57 real-time projects - Learn Python

Typing test is very useful as it helps in improving your typing speed and accuracy. This Python project will help you to develop your own typing test by following the procedures mentioned below.

About Typing Test Project

In this project, we will develop a typing test that will help in improving your speed and accuracy. The user will be given 60 seconds and the user has to write as many words as possible that are displayed on the screen within the given time frame. After completion of time the final score will be displayed to the user along with the number of wrong words entered.

Python Typing Test Project

The objective of the project is to develop our own typing test with the help of tkinter.

Project Prerequisites

To begin the project you should install pygame on your PC. This project requires the knowledge of functions in python and pygame.

Download Typing Test Python Project

Please download source code of python typing test from the following link: Python Typing Test Project Code

Project File Structure

1. Install Tkinter

2. Importing Libraries

3. Initializing test window and variables

4. Function for making the text float on the top of the window

5. Function for calculating time

6. Game Function

7. Defining labels

1. Install Tkinter:

Tkinter is a standard graphical user interface library that is available for python. You need to install Tkinter to begin the project. Write the command given below to install Tkinter on your system.

pip install tkinter

2. Importing Libraries:

from words import words
from tkinter import *
import random
from tkinter import messagebox

Code Explanation:

a. words: words is another file that contains a list of words that will be displayed on the screen.
b. random: It helps in generating random strings and numbers.
c. messagebox: It helps in displaying a message box on the screen.

3. Initializing test window and variables:

Mainscreen= Tk()
Mainscreen.geometry('800x600')
Mainscreen.title('Typing Test By DataFlair')
Mainscreen.config(bg="orange")

score=0
missed=0
time=60
count1=0
movingwords=''

Code Explanation:

a. Tk(): It helps in initializing the tkinter module.

b. geometry(): It defines the geometry of the typing test window.

c. title(): It displays the title on the top of the typing test window.

d. bg: It helps in applying the background color of the typing test window.

e. Score: It is a variable that stores the score.

f. Missed: This variable stores all the misspelled words entered by the user.

g. time: This variable stores the time allotted to complete the test.

4. Function for making the text float on the top of the window:

def movingtext():
global count1,movingwords
floatingtext='Typing Test By DataFlair'
if count1>= len(floatingtext):
count1 =0
movingwords =''
movingwords += floatingtext[count1]
count1 +=1
fontlabel.configure(text=movingwords)
fontlabel.after(150,movingtext)

Code Explanation:

a. movingtext(): This function will help the text to move on the top of the screen.

b. floatingtext: This variable stores the text that needs to be floated.

c. configure(): Overwriting over a label widget is performed by configure().

d. after(): This method schedules an action after a timeout has elapsed.

5. giventime Function:

def giventime():
global time,score,missed
if time>11:
    pass
else:
    timercount.configure(fg='red')
if time>0:
    time -=1
    timercount.configure(text=time)
    timercount.after(1000,giventime)
else:
    gameinstruction.configure(text='Hit = {} | Miss = {} | Total Score = {}'
.format(score,missed,score-missed))
rr= messagebox.askretrycancel('Notification','Do you want to play again?')
if rr==True:
score=0
missed=0
time=60
timercount.configure(text=time)
labelforward.configure(text=words[0])
scorelabelcount.configure(text=score)
wordentry.delete(0, END)

Code Explanation:

a. askretrycancel(): This function displays a retry or cancel dialog.
b. delete(): It deletes the text in the widget.

6. Game Function:

def game(event):
global score, missed
if time==60:
giventime()
gameinstruction.configure(text='')
startlabel.configure(text='')
if wordentry.get()== labelforword['text']:
score +=1
scorelabelcount.configure(text=score)
else:
missed +=1
random.shuffle(words)
labelforward.configure(text=words[0])
wordentry.delete(0,END)

Code Explanation:

a. get(): It returns the current text as a string.
b. random.shuffle(): It shuffles the original list.

7. Defining labels:

fontlabel=Label(Mainscreen,text='',font=('arial',25,
'italic bold'),fg='purple',width=40)
fontlabel.place(x=10,y=10)
movingtext()

startlabel=Label(Mainscreen,text='Start Typing',font=('arial',30,
'italic bold'),bg='black',fg='white')
startlabel.place(x=275,y=50)

random.shuffle(words)
labelforward=Label(Mainscreen,text=words[0],font=('arial',45,
'italic bold'),fg='green')
labelforward.place(x=250,y=240)

scorelabel=Label(Mainscreen,text='Your Score:',font=('arial',25,
'italic bold'),fg='red')
scorelabel.place(x=10,y=100)

scorelabelcount=Label(Mainscreen,text=score,font=('arial',25,
'italic bold'),fg='blue')
scorelabelcount.place(x=150,y=180)

labelfortimer=Label(Mainscreen,text='Time Left:',font=('arial',25,
'italic bold'),fg='red')
labelfortimer.place(x=600,y=100)

timercount=Label(Mainscreen,text=time,font=('arial',25,
'italic bold'),fg='blue')
timercount.place(x=600,y=180)

gameinstruction= Label(Mainscreen,text='Hit enter button after typing the word',
font=('arial',25,'italic bold'),fg='grey')
gameinstruction.place(x=150,y=500)

wordentry= Entry(Mainscreen,font=('arial',25,'italic bold'),bd=10,justify='center')
wordentry.place(x=250,y=330)
wordentry.focus_set()

Mainscreen.bind('<Return>',game)
mainloop()

Code Explanation:

a. label(): It is used to implement display boxes.

b. place(): It defines the place of the label on the screen.

c. Startlabel: It displays the text start typing on the screen.

d. Scorelabel: It displays the text of your score on the screen.

e. scorelabelcount: It displays the score of the user on the screen.

f. labelfortimer: It displays the text of time left on the screen.

g. Entry(): This widget accepts the single line input from the user.

h. focus_set(): It refers to the widget that is accepting inputs.

i. bind(): bind() deals with events. It helps in binding the functions and methods to an event.

j. mainloop(): It runs the program.

Python Typing Test Output:

python typing test output

Summary:

We have successfully developed a typing test project in python. We learned the practical usage of Tkinter while developing the project.

You give me 15 seconds I promise you best tutorials
Please share your happy experience on Google

follow dataflair on YouTube

4 Responses

  1. doddabasava says:

    chaligeri

  2. doddabasava says:

    ch

  3. Ankit Kumar says:

    Andaman and Nicobar Island and Lakshadweep Ialand vegetation

  4. harish says:

    this is good but we need to improve more means you should give more information

Leave a Reply

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