0
## 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.

Book Of Flames
  • 316
  • 3
  • 13
  • Everything other than the button perfectly works without any issue, but I have no idea how to drop a resume and pause button in this sort of timer. Any hint/solutions? Thanks! – Book Of Flames Jun 04 '20 at 13:43
  • Why do you use a generator? Look at the modul time https://stackoverflow.com/questions/2400262/how-to-create-a-timer-using-tkinter – Thingamabobs Jun 04 '20 at 15:53
  • I'd to use generator for adding the button, so that the timer can be stopped at the user's wish. – Book Of Flames Jun 05 '20 at 03:29
  • The major problem in the code is the `krejia()` function which is looping itself. I wanted to use for loop instead. This loop prevents any kind of simple interruption e.g. - continue and break statements. – Book Of Flames Jun 05 '20 at 03:37

0 Answers0