2024-04-25 08:33:20 发布
网友
情景:我正试图编写一个命令行程序,打印以下内容
Some text 1 Some text 2 ------------------------------------------------------- Anchored text : Time now is: 12:00
我只想不断地更新Some text 1和Some text 2,但是Anchored text将以与其他更新不同的速度更新
Some text 1
Some 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)
这个小例子可能会对你有所帮助
相关问题 更多 >
编程相关推荐