到目前为止,我想出的唯一方法是清除控制台,然后再显示一个字母的字符串。建议?
当前代码:
import os
import time
In=list(input("Text to be displayed: "))
Out=""
Move=[]
print("-")
while len(Move)<len(In):
Move+=["/","|","\\","-"]
for a in range(0,len(In)):
if In[a]==" ":
x=.3
elif In[a] in ",';:!@#$%^&*()_+-=[]{}":
x=.25
elif In[a] in "aeiouzxcvbnm1234567890AEIOUZXCVBNM":
x=.2
else:
x=.15
os.system('cls')
Out+=In[a]
print(Out+Move[a])
time.sleep(x)
os.system('cls')
print(Out)
input()
最佳答案
只需使用 print()
和 end=''
保持在同一行,flush = True
用于计时:
import time
Move+=["/","|","\\","-"]
text = input('Text to be displayed: ')
for i in text:
print(i, end='', flush=True)
time.sleep(0.1)
print('\n')
这运行为:
bash-3.2$ python3.3 test.py
Text to be displayed: This is a test
This is a test
bash-3.2$
解决您的评论,请使用以下代码:
import time
Move=["/","|","\\","-",""]
text = input('Text to be displayed: ')
for i in range(len(text)):
print(text[i]+Move[i%5], end='', flush=True)
time.sleep(0.1)
print('\n')
关于python - 使文本看起来像是在 Python Shell 中输入的,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23946170/