473,396 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Timer events

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 2985
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.")


Jul 18 '05 #2
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
EAS
But how do you display the time while it is going?
Jul 18 '05 #4
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
On Tue, 18 May 2004 00:48:05 GMT, "EAS" <er****@attbi.nospam.com>
wrote:
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

Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: William Bub | last post by:
Is there an accurate way to create a "stopwatch" good to 1/10 of a second? I'm not sure if I should use the timer control, or some way to access the computer timer. I found the following site...
13
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on...
11
by: Steve Jorgensen | last post by:
I've recently been playing with some UI ideas that require the user of a timer to drive animation. The problem I'm having is that Access routinely stops firing timer events for long periods of...
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
3
by: Kenny | last post by:
I am running a windows service that takes actions based on a couple System.Threading.Timers. The intervals are usually short... based on the time of day, anywhere between 1 and 5 minutes. ...
4
by: Dan | last post by:
Hi, I have a timer on a form (System.Windows.Forms.Timer - Framework 1.1) that is set to 60 seconds as sort an of inactivity monitor. If 60 seconds have elapsed without any user activity I want...
2
by: r norman | last post by:
Please excuse the cross-posting. This question was raised in microsoft.public.dotnet.general but hasn't been answered so I am trying where I can. There are two of us who have the same problem...
4
by: Ben | last post by:
Hello everybody I got confused by this problem for which I don't have a logical explanation. There is a Thread (ThreadA) which receives Events from another system thread (ThreadS). ThreadA then...
5
by: Tony Gravagno | last post by:
I have a class that instantiates two Timer objects that fire at different intervals. My class can be instantiated within a Windows Form or from a Windows Service. Actions performed by one of the...
4
by: grayaii | last post by:
Hi, I have a simple form that handles all its paint functionality like so: this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); And the entry point to this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.