curses01.py

#!/usr/bin/python3
# ===================================================================
# screen row/column coordinates
#
#        (0,0)   COLUMN
#          + --------------->
#          |
#     ROW  |
#          |
#          |
#          V
#
# ===================================================================

import curses
from curses import wrapper
import queue
import time

# -------------------------------------------------------------------
# ---- main function
# -------------------------------------------------------------------

def main(stdscr):

    # ---- create color (id,forground,background)

    curses.init_pair(1,curses.COLOR_RED,curses.COLOR_BLACK)
    curses.init_pair(2,curses.COLOR_WHITE,curses.COLOR_BLACK)
    red_black = curses.color_pair(1)
    white_black = curses.color_pair(2)

    # ---- clear screen

    stdscr.clear()

    loop_count = 12 

    while True:

        # ---- refresh screen

        stdscr.refresh()

        # ---- add text (row,col,text,color)

        if loop_count % 2:
            stdscr.addstr(5,5,'hello world',red_black)
        else:
            stdscr.addstr(5,5,'hello world',white_black)

        # ---- decrement loop counter (test loop)

        if loop_count > 0:
            loop_count -= 1
        else:
            break

        # ---- wait for 0.25 seconds the do it again

        time.sleep(0.25)


# -------------------------------------------------------------------
# ---- main
# -------------------------------------------------------------------

# ---- initilize curses

wrapper(main)