443,846 Members | 1,862 Online
Need help? Post your question and get tips & solutions from a community of 443,846 IT Pros & Developers. It's quick & easy.

Timer events

 P: n/a 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 Jul 18 '05 #1
5 Replies

 P: n/a 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.") Jul 18 '05 #2

 P: n/a 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.") Jul 18 '05 #3

 P: n/a But how do you display the time while it is going? Jul 18 '05 #4

 P: n/a EAS wrote: 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/ Jul 18 '05 #5

 P: n/a On Tue, 18 May 2004 00:48:05 GMT, "EAS" wrote: While this topic is still up, can someone look at my program and tell me howto keep the total time in one place? (meaning updating it instead ofprinting 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 Jul 18 '05 #6