From cbb79b8cb72909616d0a13e7361415817421ba67 Mon Sep 17 00:00:00 2001 From: Shikiryu Date: Sun, 21 May 2023 11:48:39 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20Format=20time?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tk.py | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/tk.py b/tk.py index ed3276a..e2f33bd 100644 --- a/tk.py +++ b/tk.py @@ -12,12 +12,36 @@ found_images = [] 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): global timer timer = user_data print(timer) for button in buttons: - if button['text'] == str(timer) + "s": + if button['text'] == format_seconds(timer): button.config(bg="blue") else: button.config(bg="grey") @@ -50,28 +74,10 @@ timers = [30, 45, 60, 120, 300, 600] buttons = [] for i in timers: 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") 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.pack(side="bottom")