倒数计时器中的恢复和暂停按钮

时间:2020-06-04 13:37:50

标签: python

## 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()

很长一段时间以来,我一直在用这段代码苦苦挣扎,我想为我的倒数计时器添加一个恢复和暂停按钮。我知道resume_and_pause_button()函数实际上并没有在代码中执行任何操作,但是,每次尝试都失败了。

任何帮助都会被接受。

0 个答案:

没有答案