Python Forum
Text, one letter at a time - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Text, one letter at a time (/thread-725.html)



Text, one letter at a time - MACA - Oct-31-2016

So I used to know how to do this thing where my text would be typed at a speed of 0.1 instead of immediately. But now I have forgotten it. I use to use it in games but those games were deleted. This is most of what is left. The ? is what I forgot.

def textType(text, delay):
     for ch in ???
     ??????????????
     print ("")

textType("Hello", 0.1)
HELP ME! Pray Pray Pray


RE: Text, one letter at a time - micseydel - Oct-31-2016

In Python, or a different language? Did it use curses? Was it platform-dependent?


RE: Text, one letter at a time - MACA - Oct-31-2016

Yes, it was in Python.

And No Curses

So this is what it would have looked like in a game...

#top of code
import time
gold = 0

#This is when it was in.
def textType(text, delay):
     for ch in ?????
     ?????????????
     print("")

def start():
     
     textType("Hello", 0.1)
     name = input("What is your name?")
#Bla bla bla etc.



RE: Text, one letter at a time - micseydel - Oct-31-2016

Misread your question. I think you want time.sleep(). Was thinking you wanted something people were typing into their terminal echoed back slowly, but you just want to print a whole string you already have more slowly?


RE: Text, one letter at a time - MACA - Oct-31-2016

OMG!!! YESSS!!! I REMEMBER!! Thank you. That's it


RE: Text, one letter at a time - MACA - Oct-31-2016

Wait, wait, wait. How would I use
 time.sleep(0.1) 
with the
 def textType 
function?

Like if I used it this way:

for ch in text:
    print (ch)
    time.sleep(0.1)

textType("Hello Everybody!", 0.1)



RE: Text, one letter at a time - snippsat - Oct-31-2016

In function:
time.sleep(delay)



RE: Text, one letter at a time - wavic - Nov-01-2016

(Oct-31-2016, 10:01 PM)MACA Wrote: Wait, wait, wait. How would I use
 time.sleep(0.1) 
with the
 def textType 
function?

Like if I used it this way:

for ch in text:
    print (ch)
    time.sleep(0.1)

textType("Hello Everybody!", 0.1)
Hello!
The default behavior of print() functions is to add \n - a new line - character at the end of the printed text. So the next printed text will be printed bellow.
print(ch, end="")
will fix it. The default is end="\n"