for paragraph in intro.split("\n"):
for character in paragraph:
sleep(0.06)
print(character, end="", flush=True)
print()
The above code works great (assuming you have a variable called intro, that is). Is it possible to make it so that it will stop with the sleep delay and just print all the text if the user presses any key? Or do I have to just make a y/n question about the typewriter effect in the program?
have a seperate thread running with a deadlock saying whether or not there was a keypress. If there was, then terminate. You will need to do range to get the index you are current at and print all after that index
from threading import Thread
from getkey import getkey
stop = False
def __background():
global stop
getkey()
stop = True
Thread(target = __background).start()
Sounds like a good idea but poetry and pip both fail to install getkey. It ran once and then now it crashes and can’t install getkey. I made a new Repl and had the same issue.
def typewriter(text, delay=0.06):
global stop
for paragraph in text.split("\n"):
if stop:
print(paragraph)
continue
index = 0
for character in paragraph:
if stop:
print(paragraph[index:])
break
sleep(delay)
print(character, end="", flush=True)
index+=1
if stop: continue;
print()
stop=False