Skip to content

Commit 592db06

Browse files
CountDown Timer: play alarm when coutdown reaches 0
1 parent 06a24bf commit 592db06

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

CountDown Timer/main.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ def fmt_time(seconds: int) -> str:
55
seconds = max(0, int(seconds))
66
m, s = divmod(seconds, 60)
77
return f"{m:02d}:{s:02d}"
8+
9+
try:
10+
import winsound # Windows
11+
except Exception:
12+
winsound = None
13+
14+
def play_alarm():
15+
try:
16+
if winsound:
17+
winsound.Beep(880, 300)
18+
winsound.Beep(988, 300)
19+
winsound.Beep(1047, 300)
20+
else:
21+
# macOS/Linux fallback: terminal bell
22+
print("\a", end="", flush=True)
23+
except Exception:
24+
pass
25+
826

927

1028
class Application(Frame):
@@ -89,7 +107,8 @@ def countdown(self, timeInSeconds, start=True):
89107
if timeInSeconds == 0:
90108
self._starttime=0
91109
self.labelvariable.set(fmt_time(0))
92-
return
110+
play_alarm()
111+
return
93112
if start:
94113
self._starttime = timeInSeconds
95114
if self._paused:

0 commit comments

Comments
 (0)