Simple Console Clock for Windows with Python

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.

This entry was posted in Blog Post and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

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