python 打印文本时打字机效果一样

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 打印文本时打字机效果一样相关的知识,希望对你有一定的参考价值。

# source: http://stackoverflow.com/questions/19911346/create-a-typewriter-effect-animation-for-strings-in-python

from __future__ import print_function  # lets you use print() from python 3
from time import sleep
import sys


lines = ["You have woken up in a mysterious maze",
         "The building has 5 levels",
         "Scans show that the floors increase in size as you go down"]


for line in lines:          # for each line of text (or each message)
    for c in line:          # for each character in each line
        print(c, end='')    # print a single character, and keep the cursor there.
        sys.stdout.flush()  # flush the buffer
        sleep(0.1)          # wait a little to make the effect look good.
    print('')

以上是关于python 打印文本时打字机效果一样的主要内容,如果未能解决你的问题,请参考以下文章

打字机效果文字动画

这些例子有点意思,可以研究一下哈

这些例子有点意思,可以研究一下哈

Python小技巧:用 print() 函数实现的三个特效

具有动态内容的打字机效果

JS+CSS实现CodePen首页多行打字机动画,最通俗易懂版本