palpen
5/4/2017 - 7:09 PM

Typewriter like effect when printing text

Typewriter like effect when printing text

# 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('')