0

Situation: I am trying to write a command line program that prints the following

Some text 1
Some text 2

-------------------------------------------------------
Anchored text : Time now is: 12:00

I would like to only update Some text 1 and Some text 2 constantly, but Anchored text will be updated at a different pace compared to the others.

Problem: I cannot find the right search term for what I am looking for.

Question: How do I anchor a line of text in a python command line application?

Timothy Wong
  • 565
  • 1
  • 5
  • 24

1 Answers1

1

This small example may help you.

import random
import curses
from datetime import datetime
import time

s = curses.initscr()
curses.curs_set(0)
sh, sw = s.getmaxyx()
w = curses.newwin(sh, sw, 0, 0)
w.keypad(1)
w.timeout(100)


while True:
    key = w.getch()
    if key == ord('q'):
        curses.endwin()
        quit()

    t = datetime.now()
    date_str = f"Date {t.strftime('%B %d, %Y')}"
    w.addstr(10, 10, date_str)
    time_str = f"Time now is: {t.strftime(' %X')}"
    w.addstr(sh-2, sw-50, time_str)
    time.sleep(1)
Pramote Kuacharoen
  • 1,438
  • 1
  • 2
  • 6