我想打印文本'Loading...',但它的点会前后移动(在shell中)。
我正在创建一个文本游戏,它会看起来更好。
我知道慢慢写一个字,但点也要回去。
我在想我应该忘记点回来。为此:
import sys
import time
shell = sys.stdout.shell
shell.write('Loading',"stdout")
str = '........'
for letter in str:
sys.stdout.write(letter)
time.sleep(0.1)
你觉得呢?
如果你有那个点会来回移动,那么请与我分享。
如果您需要更多的信息,我愿意提供给您。
谢谢
5条答案
按热度按时间nom7f22z1#
您可以在STDOUT中通过退格键(
\b
)使用回溯,在再次写入字符之前返回并“擦除”写入字符,以模拟动画加载,例如:请记住,这是一个阻塞过程,所以你要么必须在
for
循环中进行加载检查,要么在单独的线程中运行加载,要么在单独的线程中运行加载-只要它的本地loading
变量被设置为True
,它将保持在阻塞模式下运行。wf82jlnq2#
检查此模块Keyboard与许多功能。安装它,可能使用以下命令:
然后在Filetextdot.py中编写以下代码:
现在将文件粘贴到python文件夹中的 Lib 中。
现在你可以像下面的例子一样使用它:
谢谢
xghobddn3#
有点晚了,但对其他人来说,这并不复杂。
s4chpxco4#
我相信下面的代码就是你要找的。只需在脚本中执行此操作,在用户等待时,它将 Flink 圆点。
ogsagwnx5#
我也遇到过类似的问题。我想了很多来解决我的问题。代码应该用圆点打印“正在加载”。