import time def timer(): now = time.localtime(time.time()) return now[5] run = raw_input("Start? > ") while run == "start": minutes = 0 current_sec = timer() #print current_sec if current_sec == 59: mins = minutes + 1 print ">>>>>>>>>>>>>>>>>>>>>", mins
I want to create a kind of stopwatch that when minutes reach 20 minutes, brings up a dialog box, The dialog box is not the problem. But my minutes variable does not increment in this code.
If you're programming in Python, you're in luck: The language gives you tools to build your own timers. A timer program can be useful for not only monitoring your own time, but measuring how long your Python program takes to run.
If you've got a Python program and you want to make it wait, you can use a simple function like this one: time. sleep(x) where x is the number of seconds that you want your program to wait.
See Timer Objects from threading.
How about
from threading import Timer def timeout(): print("Game over") # duration is in seconds t = Timer(20 * 60, timeout) t.start() # wait for time completion t.join()
Should you want pass arguments to the timeout
function, you can give them in the timer constructor:
def timeout(foo, bar=None): print('The arguments were: foo: {}, bar: {}'.format(foo, bar)) t = Timer(20 * 60, timeout, args=['something'], kwargs={'bar': 'else'})
Or you can use functools.partial
to create a bound function, or you can pass in an instance-bound method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With