-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
150 lines (132 loc) · 2.9 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# Import statements:
import random
import time
import tkinter as tk
def start_test():
start_time = time.time()
phrases = [
'Good Morning.',
'Nice to meet you.',
'Happy Birthday.',
'I comb my hair.',
'I brush my teeth.',
'I like my school.',
'I love my parents.',
'My dad is my superhero.',
'I will see you tomorrow.',
'May I come in?',
'How are you?',
'How old are you?',
'What is your name?',
'The dog is happy.',
'That is a pencil.',
'It is very cold.',
'These are my books.',
'It is ten in the morning.',
'An apple is good to eat.',
'Your dress looks very nice.',
'I opened the door.',
'It is getting dark.',
'I want to eat.',
'What is your favorite color?',
'I like to eat ice cream.',
'My favorite color is blue.',
'Where are you from?',
'What is your favorite subject?',
'My father is in his office.',
]
# Pick a random sentence from the list:
phrase = random.choice(phrases)
# Set the label text to the random sentence:
label.config(
text=phrase,
)
def check_phrase():
# Calculate the elapsed time of the test:
elapsed_time = time.time() - start_time
# Get the text from the input box:
input_text = input_field.get()
# Check if the input text matches the random sentence:
if input_text == phrase:
label.config(
text='Correct! Time: {:.2f} seconds'.format(elapsed_time),
)
else:
label.config(
text='Incorrect. Try again.',
)
# Bind the "Enter" key to the check_phrase function:
root.bind(
'<Return>',
lambda event: check_phrase(),
)
# Create the Tkinter window:
root = tk.Tk()
root.geometry(
'800x600',
)
root.title(
'Typing Speed Test',
)
# Create a function to bind to the 'Clear' button:
def delete():
input_field.delete(
0,
'end',
)
# Add a label to display the random sentence:
label = tk.Label(
root,
font=(
'SF Pro Display',
18,
'bold',
),
)
label.pack(
pady=30,
)
# Add an input box for typing:
input_field = tk.Entry(
root,
font=(
'SF Pro Display',
18,
),
)
input_field.pack(
pady=30,
)
input_field.focus()
# Add a 'Start' button:
start_button = tk.Button(
root,
command=start_test,
font=(
'SF Pro Display',
18,
'bold',
),
text='START',
)
start_button.pack(
padx=30,
pady=30,
)
# Add a 'Clear' button:
clear_button = tk.Button(
root,
command=delete,
font=(
'SF Pro Display',
18,
'bold',
),
text='CLEAR',
)
clear_button.pack(
pady=30,
padx=60,
)
# Run the Tkinter event loop:
root.mainloop()