Ask coding questions

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

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 (480) [earned 5 cycles]
View Answer
ash15khng (480)

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 (17)

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

ash15khng (480)

@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 (444)

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 (17)

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