Skip to content

Instantly share code, notes, and snippets.

@tthn0
Last active July 3, 2023 10:25
Show Gist options
  • Save tthn0/5636b9b15d41d53c241f87a884490728 to your computer and use it in GitHub Desktop.
Save tthn0/5636b9b15d41d53c241f87a884490728 to your computer and use it in GitHub Desktop.
"Typewrite" effect in Python
"""A snippet for string "typewriting" in Python.
Note: On PyCharm, this effect doesnt look that good because
PyCharm outputs the letters at low FPS (on my machine).
Author: tthn0 (GitHub)
Gist Link: https://gist.github.com/tthn0/5636b9b15d41d53c241f87a884490728
"""
import sys
from time import sleep
DELAY: float = .05 # Change this to speed up/slow down typewriting speed
def typewrite(*paragraph: str) -> None:
"""This function mimics a typewriting effect by printing strings letter by letter.
Args:
*paragraph -- variable length args of setences to typewrite
"""
for sentence in paragraph:
for char in sentence:
sys.stdout.write(char)
sys.stdout.flush()
sleep(DELAY)
print()
sleep(DELAY)
# Usage (you can put as many sentences as you want)
typewrite(
"Hello World!",
"Another Sentence.",
"The quick brown fox jumps over the lazy dog.",
)
@tthn0
Copy link
Author

tthn0 commented Jan 30, 2023

@eggnaut I'm not sure! I'm not familiar with Pygame unfortunately.

Copy link

ghost commented Jan 30, 2023

@eggnaut I'm not sure! I'm not familiar with Pygame unfortunately.

Oh okay, no problemo :)

@im-nihal
Copy link

im-nihal commented Jul 2, 2023

if I am not wrong this is console based only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment