Skip to content
Sign upLog in
← Back to Community

How to add color and add scroll text to repl.

Profile icon

Can anyone help me in adding color and scroll text?

Answered by Bookie0 [earned 5 cycles]
View Answer
Profile icon
Profile icon

I'm going to assume that the language is python.

For colors, use ANSI escape codes:

# colors black = "\033[0;30m" red = "\033[0;31m" green = "\033[0;32m" yellow = "\033[0;33m" blue = "\033[0;34m" magenta = "\033[0;35m" cyan = "\033[0;36m" white = "\033[0;37m" bright_black = "\033[0;90m" bright_red = "\033[0;91m" bright_green = "\033[0;92m" bright_yellow = "\033[0;93m" bright_blue = "\033[0;94m" bright_magenta = "\033[0;95m" bright_cyan = "\033[0;96m" bright_white = "\033[0;97m" # each variable has a name of their color

To use it:

print(red + "Hello " + bright_cyan + "World!") # you can use as many colors as you want! :)

For the scrolling text (slowprint), we'll put it in a function so you can use it several times. It'll include a for loop to loop through each letter in the word and then using sleep() it'll pause before continuing to the next letter, like a typing effect.

# imports import sys, os import time st = 0.04 # initial delay between each character def sp(str): # in a function called sp with str as the parameter for letter in str: # for loop to go through each letter in the string sys.stdout.write(letter) # writes the letter sys.stdout.flush() # outputs to console without waiting time.sleep(st) # delay between each character print() # to use: sp("Hello World") # calls the function with Hello World as argument # will output the message one char at a time with 0.04 seconds # you can change st to what you want depending on how long # you want it to pause between each char

You can also use colors in that slowprint function.

Have fun and good luck! :)

(From my tutorial here) :)

Profile icon

can i add 7 colors??????????????

Profile icon


try this way.

import sys import time from termcolor import colored for x in colored("WELCOME!!!", "red"): sys.stdout.write(x) sys.stdout.flush() time.sleep(0.05)

like that.
That should work

Profile icon

If python do something like this:

import colored def scroll(str): for letter in str: sys.stdout.write(letter) sys.stdout.flush() time.sleep(0.1) print(c(), "COLOR HERE") # and to scroll: scroll('text')