Learn to Code via Tutorials on Repl.it!

← Back to all posts
Wow, it looks like this is typing... For real! - Python Typewriter effect!!
stoporinjail (123)

Hello everyone! I am going to show you how to make a typewriter effect using Python!!! It's super easy and it doesn't need to install anything.

1) Import the required modules:

from sys import stdout
import time

We will be using sys.stdout.write(), sys.stdout.flush(), and time.sleep().

2) Create a function that can write:

def write(print):
  for i in print:
    time.sleep(.1)
    stdout.write(i)
    stdout.flush()
  next = input()

You can adjust the time.sleep to your liking.
next = input() will require you to click enter before proceeding, so that you can catch up if you are a slow reader.

3) Use the function

To use the function, you can just:

print = 'Your text here'
write(print)

Or...

write("Your text here")

Either way will work.

Conclusion

If you run this, you will see it prints out with a typing effect!!

Comments
hotnewtop
stoporinjail (123)

@LeilahOntiveros did you use the

sys.stdout.flush()
stoporinjail (123)

so it's:

def write(print):
  for i in print:
    sys.stdout.write(i)
    sys.stdout.flush()
    time.sleep(.07)

@leilahOniveros

LeilahOntiveros (0)

@stoporinjail Yup i used all of the code it said for me to use.

stoporinjail (123)

Oh i found out the problem. Use the variable write instead of print and try it @LeilahOntiveros