## Importing tkinter for the stopwatch.
import tkinter as tk
## Generate an element from reverse of a given list.
def generator(x):
for each_element in reversed(x):
yield each_element
pressed = True
## Take the input of seconds only or minutes and seconds together.
minutes_seconds = input('Enter time in form (minutes seconds). ')
## A function for the working of the timer.
def krejia():
now1 = next(generator1)
now_minutes, now_seconds = now1 // 60, now1 % 60
now_minutes_str, now_seconds_str = str(now1 // 60), str(now1 % 60)
if now_seconds//10 >= 1:
label.configure(text = 'Time left: ' + now_minutes_str + ' : ' + now_seconds_str, font = 25)
else:
label.configure(text = 'Time left: ' + now_minutes_str + ' : ' + '0' + now_seconds_str, font = 25)
if pressed:
if now1 != 0 :
root.after(1000, krejia)
## For resume and pause button.(a try!)
h = []
for n in range(100):
h.append(n)
def resume_and_pause_button():
for each_element in h:
if int(each_element)%2 == 0:
pressed = True
else:
pressed = False
## if the user gives input in minutes and seconds both, do this.
if ' ' in minutes_seconds:
minutes, seconds = minutes_seconds.split(' ')
real_minutes, real_seconds = int(minutes), int(seconds)
if real_minutes >= 0 and real_seconds >= 0:
all_seconds = real_minutes*60 + real_seconds
time_values = [x for x in range(all_seconds+1)]
generator1 = generator(time_values)
root = tk.Tk()
label = tk.Label(root)
label.pack()
krejia()
tk.Button(root, text = 'resume and pause button', command = resume_and_pause_button).pack()
root.mainloop()
I'm struggling since a long time with this code and I want to add a resume and pause button to my countdown timer. I know that the resume_and_pause_button()
function doesn't really do anything in the code, but yet, every try to do so failed.
Any kind of help will be thankfully accepted.