Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Typing-Test
Submodule Typing-Test added at 8463ec
32 changes: 31 additions & 1 deletion typing_speed_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import customtkinter as ctk
import random
import time
import winsound

ctk.set_appearance_mode("light")
ctk.set_default_color_theme("blue")
Expand Down Expand Up @@ -47,7 +48,7 @@ def __init__(self):
)
self.timer_label.pack()

# SENTENCE FRAME (for better visibility)
# SENTENCE FRAME
self.sentence_frame = ctk.CTkFrame(self, width=620, height=100)
self.sentence_frame.pack(pady=20)
self.sentence_frame.pack_propagate(False)
Expand All @@ -72,6 +73,9 @@ def __init__(self):
self.input_textbox.pack(pady=10)
self.input_textbox.configure(state="disabled")

# bind key press for sound
self.input_textbox.bind("<Key>", self.play_typing_sound)

# RESULT
self.result_label = ctk.CTkLabel(
self,
Expand Down Expand Up @@ -210,6 +214,30 @@ def toggle_pause(self):
self.pause_button.configure(text="Pause")
self.update_timer()

# ======================
# PLAY TYPING SOUND
# ======================
def play_typing_sound(self, event):

if not self.timer_running:
return

typed = self.input_textbox.get("1.0", "end-1c")
index = len(typed)

if event.keysym == "BackSpace":
winsound.Beep(500, 40)
return

if index < len(self.current_sentence):

expected_char = self.current_sentence[index]

if event.char == expected_char:
winsound.Beep(800, 30) # correct key
else:
winsound.Beep(300, 80) # wrong key

# ======================
# RESULT
# ======================
Expand All @@ -220,6 +248,8 @@ def check_result(self):

self.timer_running = False

winsound.Beep(1200, 300) # completion sound

typed_text = self.input_textbox.get("1.0", "end-1c")

elapsed_time = time.time() - self.start_time
Expand Down
Loading