Advertisement
hamidy

### ruwet

Aug 28th, 2021
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. import tkinter
  2. import time
  3. import math
  4. from tkinter import *
  5. font_ = "Blackletter"
  6. reps = 0
  7. sh_break = 5
  8. lo_break = 20
  9. work_time = 25
  10. TIME = None
  11.  
  12.  
  13. def count_start():
  14. button1.config(state = tkinter.DISABLED)
  15. global reps
  16. reps += 1
  17. sh_break_sec = sh_break * 60
  18. lo_break_sec = lo_break * 60
  19. work_sec = work_time * 60
  20. if reps % 2 == 0:
  21. count_down(sh_break_sec)
  22. title_label.config(text = "S_break",bg = "#f7f5dd",fg = "Green",font = ("Times",10,"bold"))
  23. elif reps % 8 == 0:
  24. count_down(lo_break_sec)
  25. title_label.config(text = "L_break",bg = "#f7f5dd",fg = "Red",font = ("Times",10,"bold"))
  26. else :
  27. count_down(work_sec)
  28. title_label.config(text = "Work",bg = "#f7f5dd",fg = "Blue",font = ("Times",10,"bold"))
  29.  
  30.  
  31. # ----- count down -------#
  32.  
  33. def count_down(count):
  34. min = math.floor(count / 60)
  35. if min < 10:
  36. min = f"0{min}"
  37. elif min == 0:
  38. min = f"00"
  39. sec = count % 60
  40. if sec < 10 :
  41. sec = f"0{sec}"
  42. elif sec == 0:
  43. sec = f"00"
  44. conavas.itemconfig(timer,text = f"{min} : {sec} ")
  45. if count > -1 :
  46. global TIME
  47. TIME = window.after(1000,count_down,count-1)
  48. elif count <= 0 :
  49. count_start( )
  50. marks = " "
  51. sessions = math.floor(reps/2)
  52. for i in range(sessions):
  53. marks += "✔"
  54. tick.config(text = marks)
  55.  
  56. #----------Reset function-------#
  57.  
  58. def reset( ):
  59. button1.config(state = tkinter.NORMAL)
  60. window.after_cancel(TIME)
  61. title_label.config(text= "TIMER",bg = "#f7f5dd",fg = "Green")
  62. conavas.itemconfig(timer,text= "00:00")
  63. tick.config(text= " ")
  64. global reps
  65. reps = 0
  66.  
  67. #---window creation-------#
  68.  
  69. window = tkinter.Tk( )
  70. window.config(padx = 220,pady = 850,bg ="#f7f5dd")
  71.  
  72.  
  73.  
  74. #------canvas creation--------#
  75.  
  76. conavas = Canvas(width=200,height=223,bg="#f7f5dd",highlightthickness = 0)
  77.  
  78. #-------image creation---------#
  79.  
  80. tomato = PhotoImage(file="tomato.png")
  81.  
  82. #-----image storing in canvas-------#
  83.  
  84. conavas.create_image(100,111,image=tomato)
  85.  
  86. #-----create text on image------------#
  87.  
  88. timer = conavas.create_text(100,130,text = "00:00",fill = "white",font = (font_,9,"bold"))
  89.  
  90.  
  91. #------calling count down function---#
  92.  
  93.  
  94. #count_down(10) prefer fun count_start( )
  95.  
  96.  
  97. #-------labels creation----------#
  98.  
  99. #----title_label------#
  100. title_label = tkinter.Label(text="TIMER",bg = "#f7f5dd",fg = "green",font = ("Times",10,"bold"))
  101.  
  102.  
  103. #-----check label------#
  104. tick = Label(text = " ",bg = "#f7f5dd",fg = "Green")
  105.  
  106.  
  107. #------- buttons creation---------#
  108.  
  109. #---start button-----#
  110.  
  111. button1 = Button(text ="Start ", bg ="#f7f5dd",fg ="Green",command = count_start)
  112.  
  113. #-----Reset button----#
  114.  
  115. button2 = Button(text =" Reset",bg = "#f7f5dd",fg ="Red",command = reset)
  116.  
  117.  
  118. #------place all objects using grid-----#
  119.  
  120. title_label.grid( column = 1,row = 0)
  121. conavas.grid(column = 1, row = 1 )
  122. button1.grid(column = 0, row = 2)
  123. button2.grid(column = 2,row = 2)
  124. tick.grid(column = 1,row = 3)
  125.  
  126. #-------wakeup window forever-----#
  127.  
  128. window.mainloop( )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement