Answers for "should i be typing pythong"

2

python typing effect

from time import sleep
import sys

string = "The Battle Cats For Life" # Whatever string you want

for letter in string:
  sleep(0.01) # In seconds
  sys.stdout.write(letter)
  sys.stdout.flush()
Posted by: Guest on April-27-2020
0

typing test python

How to test Typing Speed using Python?

Difficulty Level : Basic
Last Updated : 05 Sep, 2020
Prerequisites: Python GUI – tkinter

#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
window.geometry("450x200")
  
x = 0
  
# defining the function for the test
def 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 lable method of tkinter for labling in window
    x2 = Label(windows, text=words[word], font="times 20")
  
    # place of labling 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 window
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.
Posted by: Guest on July-09-2021

Python Answers by Framework

Browse Popular Code Answers by Language