Please use Python 3.6 to answer the question(GUI): 9.24 Develop an application w
ID: 3849202 • Letter: P
Question
Please use Python 3.6 to answer the question(GUI):
9.24
Develop an application with a text box that measures how fast you type. It should record the time when you type the first character. Then, every time you press the blank character, it should print(1) the time you took to type the preceding word and (2) an estimate of your typing speed in words per minute by averaging the time taken for typing the words so far and normalizing over 1 minute. So, if the average time per word is 2 seconds, the normalized measure is 30 words per minute.
Please provide output screen shot and copyable code.Thank you!
Explanation / Answer
import Tkinter
import time
key_watcher = Tkinter.Tk()
#compare word input
word_compare_label = Tkinter.Label(key_watcher, text="Type the word that you want to test")
word_compare_label.pack(side=Tkinter.LEFT)
word_compare_entry_box = Tkinter.Entry(key_watcher)
word_compare_entry_box.pack(side=Tkinter.LEFT)
#type word input
word_type_label = Tkinter.Label(key_watcher, text="Repeat the word in your normal typing speed to calculate the time")
word_type_label.pack(side=Tkinter.LEFT)
word_type_entry_box = Tkinter.Entry(key_watcher)
word_type_entry_box.pack(side=Tkinter.RIGHT)
word_compare_entry_box.focus()
def pressed(keyevent):
#compare word parameters
compare_word = word_compare_entry_box.get()
compare_word_size = len(compare_word)
compare_word_list = tuple(compare_word)
compare_word_first_letter = str(compare_word_list[0])
compare_word_last_letter = str(compare_word_list[-1])
#type word parameters
type_word = word_type_entry_box.get()
type_word_size = len(type_word)
if type_word_size > 0:
type_word_list = tuple(type_word)
type_word_first_letter = str(type_word_list[0])
type_word_last_letter = str(type_word_list[-1])
if compare_word_size == 1 and type_word_size == 1:
#Even though you measure time, it is insignificant! Also, it returns 0...
print "It's just one letter... You at least need a two letter word to calculate the time!"
if type_word_size == 1 and compare_word_size > 1 and compare_word_first_letter == keyevent.char:
global start
start = time.time()
if type_word_size == compare_word_size and type_word_size != 1:
print "Match"
if compare_word_last_letter == type_word_last_letter:
stop = time.time()
total_time = stop-start
if compare_word == type_word:
print "You took " + str(float(total_time)) + " seconds to type the word " + str(compare_word) + "."
else:
print "You took " + str(float(total_time)) + " seconds to type the word that was similar to " + str(compare_word) + "."
print "Though the words are of the same size, it doesn't appear that the two words match! Retry again for accurate results..."
word_type_entry_box.bind('<KeyRelease>', pressed)
key_watcher.mainloop()