Test/Python(20220101~)

Days28. Timer 계속 (Dynamic Typing)

kiostory 2022. 5. 18. 12:00

https://stackoverflow.com/questions/11328920/is-python-strongly-typed

 

Is Python strongly typed?

I've come across links that say Python is a strongly typed language. However, I thought in strongly typed languages you couldn't do this: bob = 1 bob = "bob" I thought a strongly typed language ...

stackoverflow.com

 

 

from tkinter import *
import math
# ---------------------------- CONSTANTS ------------------------------- #
PINK = "#e2979c"
RED = "#e7305b"
GREEN = "#9bdeac"
YELLOW = "#f7f5dd"
FONT_NAME = "Courier"
WORK_MIN = 10
SHORT_BREAK_MIN = 5
LONG_BREAK_MIN = 20
# ---------------------------- TIMER RESET ------------------------------- # 
# ---------------------------- TIMER MECHANISM ------------------------------- #
def start_timer():
    count_down(WORK_MIN * 60)
# ---------------------------- COUNTDOWN MECHANISM ------------------------------- # 
# import time
# counter = 5
#
# while True:
#     time.sleep(1)
#     counter -= 1
# 이벤트 드리븐(Event Driven)... 메인루프상 계속 모니터링이 되어야 한다. 위의 기능이 실행조차 되지 않는다.
# 다른 방법을 써야 한다. >> window.after()
def count_down(count):
    count_min = math.floor(count / 60)
    if count_min < 10:
        count_min = f"0{count_min}"
    count_sec = count % 60
    if count_sec < 10:
        count_sec = f"0{count_sec}"
    canvas.itemconfig(timer_text, text=f"{count_min}:{count_sec}")
    if count > 0:
        window.after(1000, count_down, count -1)
# ---------------------------- UI SETUP ------------------------------- #
window = Tk()
window.title("Pomodoro. 14May2022, kio")
window.config(padx=100, pady=50, bg=YELLOW)
Top_label = Label(text="Timer", fg=GREEN, bg=YELLOW, font=(FONT_NAME, 50, "bold"))
Top_label.grid(column=1, row=0)
canvas = Canvas(width=200, height=224, bg=YELLOW, highlightthickness=0)
tomato_img = PhotoImage(file="tomato.png")
canvas.create_image(100,112,image=tomato_img)
pre = ""
if WORK_MIN < 10:
    pre = "0"
timer_text = canvas.create_text(102,128,text=f"{pre}{WORK_MIN}:00", fill="white",font=(FONT_NAME, 26, "bold"))
#canvas.pack()
canvas.grid(column=1, row=1)
start_button = Button(text="Start", command=start_timer, highlightthickness=0)
start_button.grid(column=0 , row=3)
reset_button = Button(text="Reset", highlightthickness=0)
reset_button.grid(column=3 , row=3)
check_mark = Label(text="♡", bg=YELLOW, fg=GREEN, font=(FONT_NAME, 20, "bold"))
check_mark.grid(column=1, row=4)
window.mainloop()

 

10분 미만, 10초 미만이 표현될때 자리수를 맞췄다.