Skip to content

Commit 71a7f08

Browse files
committed
1st commit
0 parents  commit 71a7f08

File tree

4 files changed

+150
-0
lines changed

4 files changed

+150
-0
lines changed

Timer.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import time
2+
import playsound
3+
4+
def tocar_som():
5+
"""Reproduz um arquivo WAV usando playsound."""
6+
playsound.playsound('/Users/g/Documents/G/_PROJECTS/PYTHON/Timer/timer2.wav', True)
7+
8+
def definir_timer(tempo_em_minutos):
9+
"""
10+
Cria um timer que, ao atingir o tempo especificado, toca um som.
11+
"""
12+
try:
13+
tempo_em_segundos = float(tempo_em_minutos) * 60 # Convertendo minutos para segundos
14+
if tempo_em_segundos <= 0:
15+
print("O tempo deve ser maior que 0.")
16+
return
17+
18+
print(f"Timer definido para {tempo_em_minutos} minutos ({tempo_em_segundos} segundos)...")
19+
time.sleep(tempo_em_segundos)
20+
tocar_som()
21+
22+
except ValueError:
23+
print("Entrada inválida. Por favor, insira um número inteiro para o tempo.")
24+
25+
if __name__ == "__main__":
26+
while True:
27+
try:
28+
tempo = input("Digite o tempo em minutos (ou 'sair' para encerrar): ")
29+
if tempo.lower() == 'sair':
30+
break
31+
definir_timer(tempo)
32+
except KeyboardInterrupt:
33+
print("\nTimer interrompido.")
34+
break

Timer_UI.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# pyinstaller --windowed --onefile --name "TimerApp" --icon=icon.ico --add-data "timer2.wav:." Timer_UI.py;
2+
3+
import tkinter as tk
4+
import time
5+
import os
6+
from playsound import playsound
7+
8+
import sys
9+
import os
10+
11+
def resource_path(filename):
12+
if hasattr(sys, '_MEIPASS'):
13+
return os.path.join(sys._MEIPASS, filename)
14+
return os.path.join(os.path.abspath("."), filename)
15+
16+
AUDIO_PATH = resource_path("timer2.wav")
17+
18+
19+
class TimerApp:
20+
def __init__(self, root):
21+
self.root = root
22+
root.title("Timer App")
23+
24+
self.always_on_top = True
25+
self.root.attributes("-topmost", True)
26+
27+
self.top_button = tk.Button(root, text="Top ON/OFF", command=self.toggle_top)
28+
self.top_button.grid(row=3, column=0, columnspan=4)
29+
30+
self.time_left = 0
31+
self.running = False
32+
33+
self.time_label = tk.Label(root, font=('Helvetica', 48))
34+
self.time_label.grid(row=0, column=0, columnspan=4)
35+
36+
self.start_stop_button = tk.Button(root, text="Start/Stop", command=self.start_stop, width=10)
37+
self.start_stop_button.grid(row=1, column=0, columnspan=2)
38+
39+
self.restart_button = tk.Button(root, text="Restart", command=self.restart, width=10)
40+
self.restart_button.grid(row=1, column=2, columnspan=2)
41+
42+
self.time_entry = tk.Entry(root, width=10)
43+
self.time_entry.grid(row=2, column=0, columnspan=2)
44+
self.time_entry.insert(0, "10")
45+
46+
self.set_button = tk.Button(root, text="Set", command=self.set_time, width=10)
47+
self.set_button.grid(row=2, column=2, columnspan=2)
48+
49+
self.footer = tk.Label(root, text="© 2025 TimerApp by guilhermemartins.net", font=("Helvetica", 11), fg="grey")
50+
self.footer.grid(row=99, column=0, columnspan=4, sticky="we", pady=5)
51+
52+
53+
54+
def toggle_top(self):
55+
self.always_on_top = not self.always_on_top
56+
self.root.attributes("-topmost", self.always_on_top)
57+
58+
if self.always_on_top:
59+
self.top_button.config(text="Top: ON")
60+
else:
61+
self.top_button.config(text="Top: OFF")
62+
63+
64+
def set_time(self):
65+
try:
66+
minutes = float(self.time_entry.get())
67+
self.time_left = minutes * 60 # converter para segundos
68+
self.time_label.config(text=time.strftime("%M:%S", time.gmtime(self.time_left)))
69+
except:
70+
self.time_label.config(text="Invalid")
71+
72+
def start_stop(self):
73+
if self.running:
74+
self.running = False
75+
self.time_label.config(text="Stopped", fg="white")
76+
else:
77+
self.running = True
78+
self.time_label.config(fg="white")
79+
self.timer()
80+
81+
def restart(self):
82+
self.running = False
83+
try:
84+
minutes = float(self.time_entry.get())
85+
self.time_left = int(minutes * 60) # minutos -> segundos
86+
self.time_label.config(
87+
text=time.strftime("%M:%S", time.gmtime(self.time_left)),
88+
fg="white"
89+
)
90+
except:
91+
self.time_left = 0
92+
self.time_label.config(text="Invalid", fg="white")
93+
94+
95+
def timer(self):
96+
if self.running:
97+
time_str = time.strftime("%M:%S", time.gmtime(self.time_left))
98+
self.time_label.config(text=time_str)
99+
100+
self.time_left -= 1
101+
102+
if self.time_left < 0:
103+
self.running = False
104+
self.time_label.config(text="Time's Up!", fg="white")
105+
playsound(AUDIO_PATH) # caminho para o ficheiro
106+
107+
else:
108+
self.root.after(1000, self.timer)
109+
110+
def main():
111+
root = tk.Tk()
112+
app = TimerApp(root)
113+
root.mainloop()
114+
115+
if __name__ == "__main__":
116+
main()

icon.ico

2.28 KB
Binary file not shown.

timer2.wav

58.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)