它需要您移动光标位置。我给你写了一封很难写的信。
这个脚本依赖于progress bar模块假设您在一条新的直线上绘制进度条。只需向上移动光标(使用“向上移动光标1行”的转义代码)和向下移动光标(只需使用换行符)。我也可以使用一个转义代码,但换行更容易和更快),一个可以维护多个进度条。import progressbar, time, sys
def up():
# My terminal breaks if we don't flush after the escape-code
sys.stdout.write('\x1b[1A')
sys.stdout.flush()
def down():
# I could use '\x1b[1B' here, but newline is faster and easier
sys.stdout.write('\n')
sys.stdout.flush()
# Total bar is at the bottom. Move down to draw it
down()
total = progressbar.ProgressBar(maxval=50)
total.start()
for i in range(1,51):
# Move back up to prepare for sub-bar
up()
# I make a new sub-bar for every iteration, thinking it could be things
# like "File progress", with total being total file progress.
sub = prog