scroll text
hey does anyone know how to make a script for scroll text in python? if anyone does please let me know (only if you agree to the idea of me stealing your code). thanks. =]
import time def typewriter(text, delay=0.1): for letter in text: print(letter, end='', flush=True) time.sleep(delay) print() typewriter("I'm being typed at a rate of 0.1 seconds") typewriter("I'm being typed at a rate of 0.05 seconds", 0.05)
oh and btw, for user input, try this function:
import time def typewriterinput(text, delay=0.1): for letter in text: print(letter, end='', flush=True) time.sleep(delay) print() return input() print("you said %s" % (typewriterinput("say something: ")))
when i try using a variable for the input for example if i ask them their name, and then use a typewriter statement, it gives me an error
@DiegoCamacho3 you forgot the %'s, also i recommend doing it like this:
typewriter(f"you typed: {input("type something")}!")
also I overwrite the print
function and make it accept any amount of arguments, have a separator, and an end:
def print(*data, interval=0.04, sep=None, end=None): import sys, time for i in data: for x in i: sys.stdout.write(x) time.sleep(interval) sys.stdout.flush() if sep != None: print(sep) if end != None: print(end) # so that i can use normal syntax: print("hi, " input("what is your name?"), "!") # it works!
this way, I can add it to old programs, won't have to switch between syntax, and it i don't want it, can just comment it out
thank you for your time.
make sure to copy all of the text, but use it like an input()
statement. @DiegoCamacho3
Try this:
import sys import time for x in ("WELCOME"): sys.stdout.write(x) sys.stdout.flush() time.sleep(0.05)
That should work
it didnt work
@DiegoCamacho3 did it at least type welcome? Because if you are using a like scrollTxt()
it won't work
You forgot something lol.
I think having the time module imported is key to using time.sleep
@MocaCDeveloper ah yes, thanks for reminding me.
Yup figured it would help out :)
@RYANTADIPARTHI put it in a function
Scroll text?
@MocaCDeveloper yes, text that doesn't go immediately like the default one, but one character at a time.
Oh. Hmm.
import sys from time import sleep str_ = input("Something: ") for i in str_: sys.stdout.write(i) sys.stdout.flush() sleep(.25)
^^ that should work :D
@MocaCDeveloper ok ill try it out
Aright let me know if it works!
it does work but is there a prefix to change the print statement? so for example:
scrollTxt("something")
so basically like the scroll text replaces the print statement.
No I believe not. I believe this is the only way :)
I mean. you can make a function yourself that contains the code to make the "scroll text" affect:
import sys from time import sleep def scrollTxt(text,seconds = .45): for i in text: sys.stdout.write(i) sys.stdout.flush() sleep(seconds) scrollTxt('yo dude',1) // prints each character every other second
@MocaCDeveloper
thanks
Did it help out?
from my tutorial here:
Now this typewriter effect is super cool, because it makes the text print one letter at the time. You can regulate it so that it prints the text fast or slow.
First the imports then the code in a function:
I usually put it at
0.04
because it prints it not too fast and not too slow. But you can change it. Just change the value afterst
Each time you want to do this typewriter effect, just do:
Output:
@Bookie0 hi, ive been using this and its pretty good. however, whenever i use this for an input, it immediately replies with "None" (i'll paste some code below to show you what i mean) - any help would be greatly appreciated.