[Tutor] Making a function run every second.
Peter Otten
__peter__ at web.de
Tue Nov 29 16:31:36 CET 2011
Mic wrote:
> I want a function to run every second , how do I do that?
>
> Say that the function look like this:
>
> def hi():
> print("hi")
For a console app you could use a for-loop with time.sleep() or
http://docs.python.org/dev/py3k/library/sched.html
For a script that uses tkinter there's the after() method.
Example:
root = Tk()
def hi():
print("ho")
def hi_reschedule():
hi()
# make tkinter call it again after 1000 milliseconds
root.after(1000, hi_reschedule)
hi_reschedule() # call it manually the first time
http://infohost.nmt.edu/tcc/help/pubs/tkinter/universal.html
More information about the Tutor
mailing list