1import time
2import pyttsx3
3
4def countdown(t):
5 while t:
6 mins, seconds = divmod(t, 60)
7 timer = "{:02d}:{:02d}".format(mins,seconds)
8 print(timer, end="\r")
9 time.sleep(1)
10 t -= 1
11
12 pyttsx3.speak("Beep Beep Beep Beep Beep Beep")
13 pyttsx3.speak("Timer has completed")
14 print("Timer has done")
15timer = int(input("Enter the time in seconds:- "))
16
17print(countdown(timer))
1import tkinter as tk
2
3
4class ExampleApp(tk.Tk):
5 def __init__(self):
6 tk.Tk.__init__(self)
7 self.label = tk.Label(self, text="", width=10)
8 self.label.pack()
9 self.remaining = 0
10 self.countdown(10)
11
12 def countdown(self, remaining = None):
13 if remaining is not None:
14 self.remaining = remaining
15
16 if self.remaining <= 0:
17 self.label.configure(text="time's up!")
18 else:
19 self.label.configure(text="%d" % self.remaining)
20 self.remaining = self.remaining - 1
21 self.after(1000, self.countdown)
22
23if __name__ == "__main__":
24 app = ExampleApp()
25 app.mainloop()