Timer events

L

Laughlin, Joseph V

If I want a function to be called every second, how would I do this?
Would I use timer events?

Joe Laughlin
Phantom Works - Integrated Technology Development Labs
The Boeing Company
 
E

EAS

While this topic is still up, can someone look at my program and tell me how
to keep the total time in one place? (meaning updating it instead of
printing it each time.)

--------------------------------------------


# Timer, lets the user input a time then alerts with
# system bell when that time is up.

h = 0
m = 0
s = 0

hou = 24
min = 60
sec = 60

print "Enter the hours, minutes, and seconds you want the computer to wait."

while hou < 0 or hou > 23:
hou = input("Hours: ")
while min < 0 or min > 59:
min = input("Minutes: ")
while sec < 0 or sec > 59:
sec = input("Seconds: ")

print

import time

while True:
time.sleep(1)
s += 1
if s == 60:
s = 0
m += 1
if m == 60:
m = 0
h += 1
print h, ":", m, ":", s
if h == hou and m == min and s == sec:
break

print "\a\a\a"

exit = raw_input("\nPress enter to exit.")
 
J

Jeff Epler

umm, why not convert the given time into seconds, and then call sleep
once?

def get_time(): # taken from EAS' code
print "Enter the hours, minutes, and seconds you want the computer to wait."

while hou < 0 or hou > 23:
hou = input("Hours: ") # All the usual warnings about input() apply
while min < 0 or min > 59:
min = input("Minutes: ")
while sec < 0 or sec > 59:
sec = input("Seconds: ")

# my innovation
return sec + 60 * min + 60 * 60 * hou

time.sleep(get_time())
print "\a\a\a"

exit = raw_input("\nPress enter to exit.")
 
M

Mike C. Fletcher

EAS said:
But how do you display the time while it is going?
When asking a question, try to provide a little (okay, in this case, a
*lot*) more context. Sure, there's a thread somewhere back in the
bit-bucket that one could dredge out to figure out approximately what's
being asked, but you're starting your mail out with "but", which
suggests that you're discarding the rest of the thread's suggestions.

I, for instance, often display the time while it is going by hanging a
clock in my office, but that's not likely the solution you're looking
for. Similarly, I can display time in my VR contexts by hooking up
OpenGLContext's timer object to a Text node to display the current time
in a manner that polls only at frame-refresh time. Again, I could use
Tkinter's after method to update a clock on-screen. Or I could use a
wxPython wx.Timer object, or a wx.lib.analogclock.AnalogClock for my
wxPython projects. Or I could just format a datetime instance in a
web-site.

*Where* are you trying to display "the time"? (And what you do you mean
by "the time", I assume you don't want to display relativity-corrected
time, but there's no way to tell from the question)

Do you want to display elapsed time within your program or
calendar/clock time?

Do you really mean time-of-day, or date+time?

Do you want to display it as graphics or text?

What GUI system if you want to display as graphics?

What text environment if you want to display as text (console or web)?

What are you trying to do?

Asking the right question is most of the problem most of the time,
Mike

________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/
blog: http://zope.vex.net/~mcfletch/plumbing/
 
D

Daniel 'Dang' Griffith

While this topic is still up, can someone look at my program and tell me how
to keep the total time in one place? (meaning updating it instead of
printing it each time.) [snip]
print h, ":", m, ":", s
[snip]

This works on the Windows machine I'm
using; I don't have a Unix box handy:

Change:
print h, ":", m, ":", s
to:
print h, ":", m, ":", s, '\x0d',
or:
print "%02d:%02d:%02d\x0d" % (h, m, s),

By putting a comma at the end, the
cursor doesn't move to the next line.
By making the carraige return character
the last thing to print, the cursor
moves to the start of the current line.
The next time the time is displayed, it
overwrites the previous value, making it
look like it stays in place.

If you're running inside of an IDE, I
have no idea if this will work for you.
--dang
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,197
Messages
2,571,038
Members
47,633
Latest member
BriannaLyk

Latest Threads

Top