💄 Format time
This commit is contained in:
parent
9d305a9623
commit
cbb79b8cb7
46
tk.py
46
tk.py
@ -12,12 +12,36 @@ found_images = []
|
|||||||
timer = 0
|
timer = 0
|
||||||
|
|
||||||
|
|
||||||
|
def format_seconds(seconds):
|
||||||
|
hours = None
|
||||||
|
minutes = seconds / 60
|
||||||
|
if minutes >= 1:
|
||||||
|
if minutes >= 60:
|
||||||
|
hours = int(minutes / 60)
|
||||||
|
minutes = int(minutes % 60)
|
||||||
|
else:
|
||||||
|
minutes = int(minutes)
|
||||||
|
seconds = seconds % 60
|
||||||
|
else:
|
||||||
|
minutes = None
|
||||||
|
|
||||||
|
time = ""
|
||||||
|
if hours is not None and hours != 0:
|
||||||
|
time += str(hours) + "h"
|
||||||
|
if minutes is not None and minutes != 0:
|
||||||
|
time += str(minutes) + "m"
|
||||||
|
if seconds is not None and seconds != 0:
|
||||||
|
time += str(seconds) + "s"
|
||||||
|
|
||||||
|
return time
|
||||||
|
|
||||||
|
|
||||||
def set_timer_in_seconds(user_data):
|
def set_timer_in_seconds(user_data):
|
||||||
global timer
|
global timer
|
||||||
timer = user_data
|
timer = user_data
|
||||||
print(timer)
|
print(timer)
|
||||||
for button in buttons:
|
for button in buttons:
|
||||||
if button['text'] == str(timer) + "s":
|
if button['text'] == format_seconds(timer):
|
||||||
button.config(bg="blue")
|
button.config(bg="blue")
|
||||||
else:
|
else:
|
||||||
button.config(bg="grey")
|
button.config(bg="grey")
|
||||||
@ -50,28 +74,10 @@ timers = [30, 45, 60, 120, 300, 600]
|
|||||||
buttons = []
|
buttons = []
|
||||||
for i in timers:
|
for i in timers:
|
||||||
t = i
|
t = i
|
||||||
new_button = Button(root, text=str(t) + "s", command=partial(set_timer_in_seconds, t))
|
new_button = Button(root, text=format_seconds(t), command=partial(set_timer_in_seconds, t))
|
||||||
new_button.pack(side="left")
|
new_button.pack(side="left")
|
||||||
buttons.append(new_button)
|
buttons.append(new_button)
|
||||||
|
|
||||||
# timer_30 = Button(root, text="30s", command=lambda: set_timer_in_seconds(30))
|
|
||||||
# timer_30.pack(side="left")
|
|
||||||
#
|
|
||||||
# timer_45 = Button(root, text="45s", command=lambda: set_timer_in_seconds(45))
|
|
||||||
# timer_45.pack(side="left")
|
|
||||||
#
|
|
||||||
# timer_60 = Button(root, text="1m", command=lambda: set_timer_in_seconds(1 * 60))
|
|
||||||
# timer_60.pack(side="left")
|
|
||||||
#
|
|
||||||
# timer_120 = Button(root, text="2m", command=lambda: set_timer_in_seconds(2 * 60))
|
|
||||||
# timer_120.pack(side="left")
|
|
||||||
#
|
|
||||||
# timer_300 = Button(root, text="5m", command=lambda: set_timer_in_seconds(5 * 60))
|
|
||||||
# timer_300.pack(side="left")
|
|
||||||
#
|
|
||||||
# timer_600 = Button(root, text="10m", command=lambda: set_timer_in_seconds(10 * 60))
|
|
||||||
# timer_600.pack(side="left")
|
|
||||||
|
|
||||||
launch_button = Button(root, text="Let's draw!")
|
launch_button = Button(root, text="Let's draw!")
|
||||||
launch_button.pack(side="bottom")
|
launch_button.pack(side="bottom")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user