main.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. from constants import *
  2. from helpers import sec2text, breaks_and_colors
  3. import tkinter
  4. from tkinter import messagebox
  5. # from plyer import notification
  6. reps = 0
  7. timer = ""
  8. def start_timer():
  9. global reps
  10. answer = "yes"
  11. status = "work" if reps % 2 == 0 else "breake"
  12. if reps > 0:
  13. answer = messagebox.askquestion('Action', f'Want to {status} now?')
  14. if answer == "yes":
  15. reps += 1
  16. text, color, mins = breaks_and_colors(reps)
  17. start_btn["state"] = "disabled"
  18. reset_btn["state"] = "normal"
  19. countdown(mins * 60)
  20. title.config(text=text, fg=color)
  21. rounds = reps // 2
  22. marks = "✔" * rounds
  23. checkmark.config(text=marks)
  24. else:
  25. title.config(text=f"Next is {status}", fg=GREEN)
  26. def reset_timer():
  27. window.after_cancel(timer)
  28. canvas.itemconfig(timer_text, text="00:00")
  29. start_btn["state"] = "normal"
  30. reset_btn["state"] = "disabled"
  31. global reps
  32. reps -= 1
  33. def countdown(sec):
  34. canvas.itemconfig(timer_text, text=sec2text(sec))
  35. if sec > 0:
  36. global timer
  37. timer = window.after(1000, countdown, sec - 1)
  38. else:
  39. start_btn["state"] = "normal"
  40. # notification.notify(title="Privet", app_name="Pymodoro", message="Hello guy", timeout=10)
  41. reset_btn["state"] = "disabled"
  42. start_timer()
  43. window = tkinter.Tk()
  44. window.title("Pymodoro timer")
  45. window.config(pady=50, padx=100, bg=YELLOW)
  46. title = tkinter.Label(text="Timer", bg=YELLOW, fg=GREEN,
  47. font=("Aerial", 35, "bold"))
  48. title.grid(row=0, column=1)
  49. canvas = tkinter.Canvas(width=WIDTH, height=HEIGHT,
  50. bg=YELLOW, highlightthickness=0)
  51. tomato_img = tkinter.PhotoImage(file="tomato.png")
  52. canvas.create_image(WIDTH / 2, HEIGHT / 2, image=tomato_img)
  53. timer_text = canvas.create_text(
  54. WIDTH / 2, HEIGHT / 2 + 15, text="00:00", fill="white", font=(FONT_NAME, 35, "bold"))
  55. canvas.grid(row=1, column=1)
  56. start_btn = tkinter.Button(
  57. text="Start", command=start_timer, highlightthickness=0)
  58. start_btn.grid(row=2, column=0)
  59. checkmark = tkinter.Label(pady=20, text="", bg=YELLOW,
  60. fg=GREEN, font=("Aerial", 16))
  61. checkmark.grid(row=2, column=1)
  62. reset_btn = tkinter.Button(
  63. text="Reset", state="disabled", command=reset_timer, highlightthickness=0)
  64. reset_btn.grid(row=2, column=2)
  65. window.mainloop()