对于Windows终端,请尝试控制台模块。对于unix,curses模块可以。
这就是您在Windows上执行此操作的方式。
c = Console.getconsole()
c.text(0, -1, 'And this is the string at the bottom of the console')
通过指定-1
第二个参数,字符串位于最底行。
对于Linux,在最后一行打印的工作代码。
import time
import curses
def pbar(window):
height, width = window.getmaxyx()
for i in range(10):
window.addstr(height -1, 0, "[" + ("=" * i) + ">" + (" " * (10 - i )) + "]")
window.refresh()
time.sleep(0.5)
curses.wrapper(pbar)