Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter
- import time
- import math
- from tkinter import *
- font_ = "Blackletter"
- reps = 0
- sh_break = 5
- lo_break = 20
- work_time = 25
- TIME = None
- def count_start():
- button1.config(state = tkinter.DISABLED)
- global reps
- reps += 1
- sh_break_sec = sh_break * 60
- lo_break_sec = lo_break * 60
- work_sec = work_time * 60
- if reps % 2 == 0:
- count_down(sh_break_sec)
- title_label.config(text = "S_break",bg = "#f7f5dd",fg = "Green",font = ("Times",10,"bold"))
- elif reps % 8 == 0:
- count_down(lo_break_sec)
- title_label.config(text = "L_break",bg = "#f7f5dd",fg = "Red",font = ("Times",10,"bold"))
- else :
- count_down(work_sec)
- title_label.config(text = "Work",bg = "#f7f5dd",fg = "Blue",font = ("Times",10,"bold"))
- # ----- count down -------#
- def count_down(count):
- min = math.floor(count / 60)
- if min < 10:
- min = f"0{min}"
- elif min == 0:
- min = f"00"
- sec = count % 60
- if sec < 10 :
- sec = f"0{sec}"
- elif sec == 0:
- sec = f"00"
- conavas.itemconfig(timer,text = f"{min} : {sec} ")
- if count > -1 :
- global TIME
- TIME = window.after(1000,count_down,count-1)
- elif count <= 0 :
- count_start( )
- marks = " "
- sessions = math.floor(reps/2)
- for i in range(sessions):
- marks += "✔"
- tick.config(text = marks)
- #----------Reset function-------#
- def reset( ):
- button1.config(state = tkinter.NORMAL)
- window.after_cancel(TIME)
- title_label.config(text= "TIMER",bg = "#f7f5dd",fg = "Green")
- conavas.itemconfig(timer,text= "00:00")
- tick.config(text= " ")
- global reps
- reps = 0
- #---window creation-------#
- window = tkinter.Tk( )
- window.config(padx = 220,pady = 850,bg ="#f7f5dd")
- #------canvas creation--------#
- conavas = Canvas(width=200,height=223,bg="#f7f5dd",highlightthickness = 0)
- #-------image creation---------#
- tomato = PhotoImage(file="tomato.png")
- #-----image storing in canvas-------#
- conavas.create_image(100,111,image=tomato)
- #-----create text on image------------#
- timer = conavas.create_text(100,130,text = "00:00",fill = "white",font = (font_,9,"bold"))
- #------calling count down function---#
- #count_down(10) prefer fun count_start( )
- #-------labels creation----------#
- #----title_label------#
- title_label = tkinter.Label(text="TIMER",bg = "#f7f5dd",fg = "green",font = ("Times",10,"bold"))
- #-----check label------#
- tick = Label(text = " ",bg = "#f7f5dd",fg = "Green")
- #------- buttons creation---------#
- #---start button-----#
- button1 = Button(text ="Start ", bg ="#f7f5dd",fg ="Green",command = count_start)
- #-----Reset button----#
- button2 = Button(text =" Reset",bg = "#f7f5dd",fg ="Red",command = reset)
- #------place all objects using grid-----#
- title_label.grid( column = 1,row = 0)
- conavas.grid(column = 1, row = 1 )
- button1.grid(column = 0, row = 2)
- button2.grid(column = 2,row = 2)
- tick.grid(column = 1,row = 3)
- #-------wakeup window forever-----#
- window.mainloop( )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement