-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
77 lines (61 loc) · 3.26 KB
/
main.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
import tkinter as tk
import time
import threading
import random
class TypeSpeedGUI:
def __init__(self):
self.root = tk.Tk()
self.root.title("Typing speed tester")
self.root.geometry("800x600")
# self.text = open("text.txt", "r").read().split("\n")
self.text = "It is a long established fact that a reader will be distracted by the readable content of a page " \
"when looking at its layout. making it look like", \
"readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as " \
"their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on", \
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. " \
"Ipsum passages, and more recently with desktop publishing software like Aldus "
self.frame = tk.Frame(self.root)
self.sample_label = tk.Label(self.frame, text=random.choice(self.text), font=("Helventica", 18),
wraplength=750)
self.sample_label.grid(row=0, column=0, columnspan=2, padx=5, pady=5)
self.input_entry = tk.Entry(self.frame, width=40, font=("Helventica", 24))
self.input_entry.grid(row=1, column=0, columnspan=2, padx=5, pady=10)
self.input_entry.bind("<KeyPress>", self.start)
self.speed_label = tk.Label(self.frame, text="Speed: \n0.00 CPS\n0.00 CPM\n0.00 WPS\n0.00 WPS",
font=("Helventica", 18))
self.speed_label.grid(row=2, column=0, columnspan=2, padx=5, pady=10)
self.reset_button = tk.Button(self.frame, text="Reset", command=self.reset, font=("Helventica", 24))
self.reset_button.grid(row=3, column=0, columnspan=2, padx=5, pady=10)
self.frame.pack(expand=True)
self.counter = 0
self.running = False
self.root.mainloop()
def start(self, event):
if not self.running:
if not event.keycode in [16, 17, 18]:
self.running = True
t = threading.Thread(target=self.time_thread)
t.start()
if not self.sample_label.cget('text').startswith(self.input_entry.get()):
self.input_entry.config(fg="red")
else:
self.input_entry.config(fg="black")
if self.input_entry.get() == self.sample_label.cget('text')[:-1]:
self.running = False
self.input_entry.config(fg="green")
def time_thread(self):
while self.running:
time.sleep(0.1)
self.counter += 0.1
cps = len(self.input_entry.get()) / self.counter
cpm = cps * 60
wps = len(self.input_entry.get().split(" ")) / self.counter
wpm = wps * 60
self.speed_label.config(text=f"Speed: \n{cps:.2f} CPS\n{cpm:.2f} CPM\n{wps:.2f} WPS\n{wpm:.2f} WPM")
def reset(self):
self.running = False
self.counter = 0
self.speed_label.config(text="Speed: \n0.00 CPS\n0.00 CPM\n0.00 WPS\n0.00 WPM")
self.sample_label.config(text=random.choice(self.text))
self.input_entry.delete(0, tk.END)
TypeSpeedGUI()