如何创建旋转的命令行光标? [英] How to create a spinning command line cursor?
本文介绍了如何创建旋转的命令行光标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用Python在终端中打印旋转光标?
Is there a way to print a spinning cursor in a terminal using Python?
推荐答案
假设您的终端是这样的处理\b
Something like this, assuming your terminal handles \b
import sys
import time
def spinning_cursor():
while True:
for cursor in '|/-\\':
yield cursor
spinner = spinning_cursor()
for _ in range(50):
sys.stdout.write(next(spinner))
sys.stdout.flush()
time.sleep(0.1)
sys.stdout.write('\b')
这篇关于如何创建旋转的命令行光标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文