Simple Console Clock for Windows with Python

Wednesday, May 27th, 2009

Tags:

The code is self explanatory:

Python 3 Source Code:
———————————————-

from threading import Timer # import the Timer class
import os # import os library
import time # import time library
def main(): # define the main function
os.system(“cls”) # Windows: Clear the console (Remove last printout)
print(“Time: “+time.ctime(time.time())) # Display the time
t = Timer(1,main) # Instantiate the Timer() object with 1 sec interval — Recursive
t.start() # Start the timer

if __name__ == “__main__”: # Check if the script is being executed from console
main() # Start the program

———————————————-

It displays a clock on Windows Command Prompt and updates it every second. It mainly demonstrates the Timer object of threading library.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">