在 Python 终端中制作一个动画等待点序列



我正在做一个小项目,它都是作为脚本运行的。

在终端中,我希望在"加载"某些内容时进行一个小动画

......并在同一条线上再次 我将如何去做

我制作了清除屏幕的功能,但我如何只清除行而不在终端中暂停

对于这么简单的动画,我认为使用回车就足够了 (它将打印光标放在行首(。 ...只是不要忘记清除其他字符的空间;)

from itertools import cycle
from time import sleep
n_points = 5
points_l = [ '.' * i + ' ' * (n_points - i) + 'r' for i in range(n_points) ]
cond = True
for points in cycle(points_l):
print(points, end='')
sleep(0.1)
if not cond:
break

最新更新