+ 3

Typewriter effect on inputs (python)

So I learned how to get python to print strings horizontally over a certain period of time instead of putting out the entire string at once. Like the interface is typing: import sys,time,os message = ("hello world!) for char in message: sys.stdout.write (char) sys.stdout.flush() time.sleep (0.1) What I'm trying to figure out it how to get it to respond to input by using the same method but when I do: import sys,time,os message = input ("hello world!) for char in message: sys.stdout.write (char) sys.stdout.flush() time.sleep (0.1) It just prints everything out at once again. Anyone know how to fix? Thanks!

29th Aug 2019, 5:01 PM
AR0
AR0 - avatar
7 Answers
+ 4
I got new notified on this thread again, so I decided to read the OP question once again and now I think i understand what he meant...you can simply try this Import time a = input("enter your name : ") for char in a: time.sleep(.1) print(a, end="")
23rd Apr 2020, 11:04 PM
Mirielle
Mirielle - avatar
+ 6
Try: message = input() or "hello world" for char in message: sys.stdout.write(char) sys.stdout.flush() time.flush(0.1) ----------alternatively----------- for i,x in enumerate(message): sys.stdout.write(x) sys.stdout.flush() time.flush(0.1)
29th Aug 2019, 5:09 PM
Mirielle
Mirielle - avatar
+ 3
OP came back after 1yr to verify an answer lol
16th Nov 2020, 4:52 PM
Mirielle
Mirielle - avatar
0
Works if I don't put input. Something about that input is messing it up...
29th Aug 2019, 5:18 PM
AR0
AR0 - avatar
0
Hey! I have the same problem. It looks like when I run it through the text of an input, it wants to return “None” before the user can enter an input. Did you find a solution to this?
23rd Apr 2020, 10:07 PM
Joel
0
Mirielle[Inactive] nice! After I posted this I came to another solution: use whatever you need to for the typewriter effect, then set the input as simply “ “. So the typewriter effect only affects a string, and the imput is just a space occurring between the sentence and the actual input.
24th Apr 2020, 1:19 AM
Joel
0
Sorry bout that lol
16th Nov 2020, 5:12 PM
AR0
AR0 - avatar