Skip to content Skip to sidebar Skip to footer

Python Countdown Clock With Gui

I'm having problems with a countdown clock that I was making in Python for a Raspberry Pi. I need to have a countdown clock that counts down from 60 minutes. When time runs out it

Solution 1:

I'd recommend using generators to handle your for loop and will provide a minimal example but on StackOverflow no one is going to "write the actual timer and timer stopping part" (see What topics can I ask here)

Note this is an example I had before this question was posted and thought it would be helpful to you.

import tkinter as tk

defrun_timer():
    for time inrange(60):
        label["text"] = time #update GUI hereyield#wait until next() is called on generator

root = tk.Tk()

label = tk.Label()
label.grid()

gen = run_timer() #start generatordefupdate_timer():
    try:
        next(gen)
    except StopIteration:
        pass#don't call root.after since the generator is finishedelse:
        root.after(1000,update_timer) #1000 ms, 1 second so it actually does a minute instead of an hour

update_timer() #update first time

root.mainloop()

you will still need to figure out for yourself how to implement after_cancel() to stop it and the red "GAME OVER" text.

Post a Comment for "Python Countdown Clock With Gui"