锚文本 Python CLI 输出



>情况:我正在尝试编写一个命令行程序来打印以下内容

Some text 1
Some text 2
-------------------------------------------------------
Anchored text : Time now is: 12:00

我只想不断更新Some text 1Some text 2,但与其他更新相比,Anchored text将以不同的速度更新。

问题:我找不到适合我所查找内容的搜索词。

问:如何在 python 命令行应用程序中锚定一行文本?

这个小例子可能会对你有所帮助。

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)

最新更新