(Dec-31-2016, 10:17 PM)sparkz_alot Wrote: The one thing I notice is the lack of row 5 (0), so midnight 00:00:00 won't show up.Midnight should work just fine. It will be all zeros.
Anyway, latest version. Flickering fixed; update speed increased so we don't miss some seconds (as could happen before); deciseconds added; some overall simplifications:
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os import time import cursor import colorama as cr from datetime import datetime TAB = " " * 4 UPDATE_SPEED = 1 / 60.0 DISPLAY = cr.Style.BRIGHT + cr.Fore.RED ON = cr.Style.BRIGHT + cr.Fore.GREEN OFF = DISPLAY COLUMN_POSITIONS = (5, 7, 13, 15, 21, 23, 29) START_ROW = 3 def get_cursor_locations(column): return [cr.Cursor.POS(column, START_ROW+2*i) for i in range(4)] def render(digit, cursors): binary = bin(digit)[2:].zfill(4) for bit, cursor in zip(binary, cursors): color = ON if int(bit) else OFF print("{}{}{}".format(color, cursor, bit)) def startup(): cursor.hide() cr.init() def cleanup(message): print(DISPLAY + "\n" * 8) print(message) cursor.show() cr.deinit() def run(seconds): print(TAB.join([DISPLAY, "HRS", " MIN", " SEC"])) start_time = time.clock() while time.clock() - start_time < seconds: time_digits = map(int, datetime.now().strftime("%H%M%S%f")) for digit, column in zip(time_digits, COLUMN_POSITIONS): render(digit, get_cursor_locations(column)) time.sleep(UPDATE_SPEED) def main(): startup() seconds_to_run = 60 try: run(seconds_to_run) cleanup("{} second timer expired.".format(seconds_to_run)) except KeyboardInterrupt: cleanup("Program stopped.") if __name__ == "__main__": main()