Sie können:
def up(lines=1):
clearline = '\033[2K' # clear a line
upline = '\033[1A' # Move cursor up a line
for _ in range(lines):
sys.stdout.write(upline)
sys.stdout.write(clearline)
Danach Sie Ihre Statuszeilen erneut drucken können. Und dann:
sys.stdout.flush()
Hier ist ein volles Arbeitsprogramm demonstriert dies:
import sys
from time import sleep
def up(lines=1):
clearline = '\033[2K' # clear a line
upline = '\033[1A' # Move cursor up a line
for _ in range(lines):
sys.stdout.write(upline)
sys.stdout.write(clearline)
num_lines = 3
for i in range(10):
for l in range(num_lines):
sys.stdout.write('{} hello\n'.format(i*l+i))
sys.stdout.flush()
sleep(0.5)
up(num_lines)
Natürlich, wenn Sie eine vollständige geblasene tui machen, werden Sie wollen so etwas wie Flüche benutzen oder urwid
Hast du dir Pythons Fluch Tutorial angeschaut? https://docs.python.org/3/howto/curses.html – kay