-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFastTyping.py
More file actions
64 lines (56 loc) · 2.25 KB
/
Copy pathFastTyping.py
File metadata and controls
64 lines (56 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from tkinter import *
import time
import random as r
from dominate.tags import button
class FastTyping(Tk):
def __init__(self):
super().__init__()
self.current_word = None
self.title("Speed type")
self.minsize(width=600, height=300)
self.configure(bg="#F56E14")
self.phrases = [
"Junior developers",
"Write clean code",
"Junior programmers",
"Learn new languages",
"Debugging skills",
"Code reviews",
"Coding skills",
"I love Python",
"I love Java"
]
self.start_time = None
# Intro label
self.start_label = Label(self, text="Speed checker", font=("Arial", 24, "bold"), bg="#F56E14", fg="#F5D995")
self.start_label.pack(pady=10)
self.start_word = Label(self, text="", font=("Arial", 20, "bold"), bg="#F56E14", fg="black")
self.start_word.pack(pady=25)
# Typing Entry
self.entry = Entry(width=35,font=("Arial", 16))
self.entry.pack(pady=10)
self.entry.bind("<Return>", self.check_word)
# Result label
self.result_label = Label(self, text="", font=("Arial", 20, "bold"), bg="#F56E14", fg="black")
self.result_label.pack(pady=15)
# Reset button
self.button = Button(text="Reset", command=self.getNewPhrase, activebackground="#B6E053", activeforeground="#000000")
self.button.pack(pady=10)
self.getNewPhrase()
def getNewPhrase(self):
self.current_word = r.choice(self.phrases)
self.start_word.config(text=self.current_word)
self.entry.delete(0, END)
self.start_time = time.time()
def check_word(self, event):
typed_phrase = self.entry.get().strip()
if typed_phrase == self.current_word.lower():
elapsed_time = time.time() - self.start_time
typing_speed = int(len(self.current_word) / (elapsed_time/60))
self.result_label.config(text=f"Your speed is {typing_speed} per minute", fg="black")
else:
self.result_label.config(text=f"Input and given phrase don't match", fg="black")
self.after(1500, self.getNewPhrase())
if __name__ == "__main__":
app = FastTyping()
app.mainloop()