How to change text color in python
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?
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
-Fireweed-
@Bookie0 Thanks this one actually works!
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!
matthew-dale
@Bookie0 Thanks this really helped!
Bookie0
np :) @matthew-dale
alexanderconne2
@Bookie0 this stil dont work
LylahGeis
help me please
Solution
this is how. You can use
termcolor
module.like that.
That should work
@RYANTADIPARTHI Ok thanks
@JacobMcPherson1 no problem!
@RYANTADIPARTHI
thank you
@RYANTADIPARTHI Thanks! Wow I will use this!
@-Fireweed- No problem, glad to help :)
@AreefeenWantaha no problem :)
@RYANTADIPARTHI
This doesnt seem to work for me
@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!
@RYANTADIPARTHI will this work with other print functions like print_slow - which i used to change text speed