Skip to content
← Back to Community
How do I make colored text in Python ?
Profile icon
Joshuahaojie

Just asking this for my school project. Also, is there any way to change font or size ? If so, do let me know. Thank you !

Answered by CodingCactus [earned 5 cycles]
View Answer
Voters
Profile icon
NorthGooding
Profile icon
TomBroad
Profile icon
Jaycepeter
Profile icon
Joshuahaojie
Comments
hotnewtop
Profile icon
CodingCactus

No, there is no way to change font size.
Here is the tutorial on colouring text: https://repl.it/talk/learn/Styling-text-in-Python/33384

Profile icon
Joshuahaojie

@CodingCactus Thanks so much for the help ! I decided to use the RGB method.

Profile icon
CodingCactus

@Joshuahaojie good choice!

Profile icon
Coder100

Here's a dict that contains the most common colors. I put it in a dict so it doesn't pollute the global scope.

colors = { 'reset': '\x1b[0m', 'bold': '\x1b[1m', 'italic': '\x1b[3m', 'underline': '\x1b[4m', 'inverse': '\x1b[7m', 'black': '\x1b[30m', 'red': '\x1b[31m', 'green': '\x1b[32m', 'yellow': '\x1b[33m', 'blue': '\x1b[34m', 'magenta': '\x1b[35m', 'cyan': '\x1b[36m', 'white': '\x1b[37m', 'gray': '\x1b[90m', 'bright_red': '\x1b[91m', 'bright_green': '\x1b[92m', 'bright_yellow': '\x1b[93m', 'bright_blue': '\x1b[94m', 'bright_magenta': '\x1b[95m', 'bright_cyan': '\x1b[96m', 'bright_white': '\x1b[97m', 'bg_black': '\x1b[40m', 'bg_red': '\x1b[41m', 'bg_green': '\x1b[42m', 'bg_yellow': '\x1b[43m', 'bg_blue': '\x1b[44m', 'bg_magenta': '\x1b[45m', 'bg_cyan': '\x1b[46m', 'bg_white': '\x1b[47m', 'bg_gray': '\x1b[100m', 'bg_bright_red': '\x1b[101m', 'bg_bright_green': '\x1b[102m', 'bg_bright_yellow': '\x1b[103m', 'bg_bright_blue': '\x1b[104m', 'bg_bright_magenta': '\x1b[105m', 'bg_bright_cyan': '\x1b[106m', 'bg_bright_white': '\x1b[107m' } print(f'{colors["red"]}Red Text{colors["reset"]} {colors["bg_blue"]}text with blue background{colors["reset"]} normal text')

You can check out the wikipedia page for more information!

Profile icon
Joshuahaojie

@Coder100 Thanks for the help ! Would be very useful for my future projects

Profile icon
Coder100

Hi, please post this in ask next time.

Profile icon
Joshuahaojie

@Coder100 Sorry, didn't realize that.

Profile icon
Vandesm14

I moved your post to the Ask board, which is for asking questions

Profile icon
Joshuahaojie

@Vandesm14 Alright thanks