Python countdown clock with GUI [duplicate]

2024/7/6 11:10:12

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 should display a red text "GAME OVER".

I've already made one using TKinter and a for loop for the actual timer but I couldn't find any way to stop the for loop. I gave up on it.

Is there anyone nice enough to maybe write the actual timer and timer stopping part? I'm good enough at python and TKinter to do everything else that I need.

Answer

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 tkdef run_timer():for time in range(60):label["text"] = time #update GUI hereyield #wait until next() is called on generatorroot = tk.Tk()label = tk.Label()
label.grid()gen = run_timer() #start generator
def update_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 hourupdate_timer() #update first timeroot.mainloop()

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

https://en.xdnf.cn/q/120728.html

Related Q&A

Confidence calculation in association rule [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, argum…

How to write the names that start with A - L to one file and the rest to another?

Hello my assignment is :Create a system that allows the user to enter their name, title, surname, Dob, email and phone number. Once details are submitted, they should be written to a file. Surnames tha…

How is it possible to use a while loop to print even numbers 2 through 100?

I am a beginner and I am stuck on this problem, "Write a python code that uses a while loop to print even numbers from 2 through 100. Hint ConsecutiveEven differ by 2."Here is what I came up …

Issue with buttons not functioning after start of program

I am new and learning python 3.6 and Ive almost completed my first code project. After doing an exhaustive search to resolve my problem I have not been able to find the answer to what I am sure is a si…

explanation of C implementation pythons len function [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 5…

How to compare the attributes start with $ in 2 functions and display match or mismatch

My input file contain attributes if(match($OPTION_EnableDetails, "1") or match($OPTION_EnableDetails_juniper, "1")) {details($juniFileXferStatus,$juniFileXferTimeStamp,$juniFileXfer…

Python comparing elements in two lists

I have two lists:a - dictionary which contains keywords such as ["impeccable", "obvious", "fantastic", "evident"] as elements of the listb - sentences which cont…

Remove all keys that have values of N/A, -, or empty strings [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 2…

Sorting algorithms more efficient than bubble sort [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 7 years ago.Improve…

How can I return the odd numbers of a list, using only recursion in Python? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable…