Ask coding questions

← Back to all posts
How do I use termcolor?
AHulot (43)

Hi I have been wondering how I can change the colour of my text in the console. I just started Python. Can anyone help?

Answered by ash15khng (684) [earned 5 cycles]
View Answer
ash15khng (684)

I'm not sure how to use termcolor, but I can recommend using ANSI escape codes.

print("\033[31;44mHello World!\033[0m") # prints Hello World! with red texts and a blue background

Full tutorial:

AHulot (43)

Thank you! This will be useful in the future. @ash15khng

ash15khng (684)

@AHulot Apparently ANSI escape sequences can also be used to make terminal applications which is pretty cool. Do you mind marking my answer as correct? Thanks!

Geocube101 (590)

Termcolor module Colored and cprint examples
Note: In the following, color is a string variable from the colors listed in the link provided

from termcolor import colored, cprint
#print colored text with cprint
cprint('Hello World', color)

#print colored text with colored
print(colored('Hello World', color))
AHulot (43)

Thanks a lot. I used it and it worked! @Geocube101