Skip to content
← Back to Community
How to change text color in python
Profile icon
JacobMcPherson1

I see people with colored text in their projects all the time but I don't know how to do it. Can someone help me?

Answered by RYANTADIPARTHI [earned 5 cycles]
View Answer
Voters
Profile icon
PKThunder
Profile icon
PARKERWHITBEY
Profile icon
RobertCampbell6
Profile icon
CrystalHan
Profile icon
JacobMcPherson1
Comments
hotnewtop
Profile icon
RYANTADIPARTHI

Solution

this is how. You can use termcolor module.

from termcolor import colored print(colored("This is red"), "red") print(colored("This is blue"), "blue") print(colored("This is green"), "green") print(colored("This is orange"), "orange") print(colored("This is white"), "white") print(colored("This is grey"), "grey")

like that.
That should work

Profile icon
JacobMcPherson1

@RYANTADIPARTHI Ok thanks

Profile icon
RYANTADIPARTHI

@JacobMcPherson1 no problem!

Profile icon
AreefeenWantaha

@RYANTADIPARTHI
thank you

Profile icon
-Fireweed-

@RYANTADIPARTHI Thanks! Wow I will use this!

Profile icon
RYANTADIPARTHI

@-Fireweed- No problem, glad to help :)

Profile icon
RYANTADIPARTHI

@AreefeenWantaha no problem :)

Profile icon
BrynmorLees

@RYANTADIPARTHI
This doesnt seem to work for me

Profile icon
RobertCampbell6

@BrynmorLees same but Bookie0 down below made a great versio, just copy and paste it into you clipboard, pin it... and you will have access to this forever!

Profile icon
twinnturbo

@RYANTADIPARTHI will this work with other print functions like print_slow - which i used to change text speed

Profile icon
Bookie0

Use ANSI escape codes:

# colors Red = "\033[0;31m" Green = "\033[0;32m" Orange = "\033[0;33m" Blue = "\033[0;34m" Purple = "\033[0;35m" Cyan = "\033[0;36m" White = "\033[0;37m" black = "\033[0;30m" black = "\033[0;90m" red = "\033[0;91m" green = "\033[0;92m" yellow = "\033[0;93m" blue = "\033[0;94m" magenta = "\033[0;95m" cyan = "\033[0;96m" white = "\033[0;97m" cyan_back="\033[0;46m" pink_back="\033[0;45m" white_back="\033[0;47m" blue_back="\033[0;44m" orange_back="\033[0;43m" green_back="\033[0;42m" red_back="\033[0;41m" grey_back="\033[0;40m" bold = "\033[1m" underline = "\033[4m" italic = "\033[3m" darken = "\033[2m" reset = "\033[0m" # to use: print(red + "Hello " + bright_yellow + " World" + cyan_back + "!" + reset) # reset is for resetting back to default

Good luck! :D

Profile icon
-Fireweed-

@Bookie0 Thanks this one actually works!

Profile icon
Bookie0
Profile icon
RobertCampbell6

@Bookie0 hey thanks this one work and the example really helped me understand how to use this! and I also appreciate the fact that I can just copy and paste this whever I need it!

Profile icon
matthew-dale

@Bookie0 Thanks this really helped!

Profile icon
Bookie0
Profile icon
alexanderconne2

@Bookie0 this stil dont work

Profile icon
LylahGeis

help me please