Ask coding questions

← Back to all posts
Scrolling Text Help
[deleted]

Hello there. Please help me on how to make scrolling text for my projects.
TY,
@poetaetoes

Answered by Bookie0 (6360) [earned 5 cycles]
View Answer
Comments
hotnewtop
Bookie0 (6360)

Hi,

do you mean the typewriter effect? if yes, here's how to:

import sys, time # imports

def sp(str): # putting this in a function
  for letter in str:
    sys.stdout.write(letter)
    sys.stdout.flush()
    time.sleep(0.04) # change the number to make it faster/slower based on ur preference
  print()

to use:

sp("hello!")

will output hello in a nice typewriter effect. try it out! ;)

[deleted]

@Bookie0 wait why does it look so glitchy?

Bookie0 (6360)

hum it shouldnt look so glitchy. maybe it's too slow? in that case increase the speed. (instead of 0.05 make it 0.02 or something) @poetaetoes

[deleted]

@Bookie0 forgot to mark it a long time ago :\

Coder100 (18893)

Here you go!

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)
[deleted]

@Coder100 not working

Coder100 (18893)

make sure its not like your errors lol @poetaetoes

[deleted]

@Coder100 run it

Coder100 (18893)

@poetaetoes line 99:

  elif change == 0:
    print("\n You can have " + str(quarters) + " quarters, " + str(dimes) + " dimes, " + str(nickels) + " nickels, " + str(pennies) + " pennies. \n\n\n\n\n" <-- forgot ')'
Coder100 (18893)

yeah its your errors not mine smh @poetaetoes

Coder100 (18893)

@poetaetoes
you forgot parentheses on line 100 :/

  elif change == 0:
    print("\n You can have " + str(quarters) + " quarters, " + str(dimes) + " dimes, " + str(nickels) + " nickels, " + str(pennies) + " pennies. \n\n\n\n\n")

baf

Coder100 (18893)

oh and btw, to use it for input, use this function:

def typewriterinput(text, delay=0.05):
  for letter in text:
    print(letter, end='', flush=True)
    time.sleep(delay)
  return input()

@poetaetoes