-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintervaltimer4.py
70 lines (55 loc) · 1.73 KB
/
intervaltimer4.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
import datetime
import winsound
import tkinter as tk
import os
import time
# Define the interval time in five minutes
interval = 5
instance = 0
def set_target_time():
instance = 0
#current time
current_time = datetime.datetime.now()
# Calculate the next multiple of the interval time
minute = current_time.minute
if minute % interval != 0:
minute = ((minute // interval) + 1) * interval
if minute == 60:
minute = 0
current_time += datetime.timedelta(hours=1)
# Set the target time
target_time = current_time.replace(minute=minute, second=0, microsecond=0)
return target_time
def check_time():
# Get the current time and target time
current_time = datetime.datetime.now()
target_time = set_target_time()
instance = 0
# Check if it's time to switch
if current_time >= target_time:
# Play the sound
#winsound.PlaySound("C:\\Users\\visha\\OneDrive\\Desktop\\Ding Ding Iphone.mp3", winsound.SND_FILENAME)
if instance < 1:
os.startfile(r"C:\Users\visha\OneDrive\Desktop\Ding Ding Iphone.mp3")
blink(60)
time.sleep(60)
# Update the target time
target_time = set_target_time()
instance = 0
# Update the label
time_label.config(text=current_time.strftime("%H:%M:%S"))
# Schedule the next check
time_label.after(1000, check_time)
def blink():
time_label.config(bg="red")
time_label.after(500, lambda: time_label.config(bg=window.cget("bg")))
# Create the tkinter window
window = tk.Tk()
window.title("Interval Timer")
# Create the time label
time_label = tk.Label(window, font=("Arial", 50))
time_label.pack()
# Start the timer
check_time()
# Run the window
window.mainloop()