RGB colors in Python

Many people use ANSI color codes when styling in Python. But these have disadvantages. Mainly, they are very hard to remember. So, I’m going to tell you an alternative to this: RGB styling.

RGB color escape sequences are formatted like this: \033[38;2;<r>;<g>;<b>m.
If you wanted to do RGB in the background, you would do it like this: \033[48;2;<r>;<g>;<b>m


reset = "\033[0m"
bold = "\033[1m"
white = "\033[38;2;255;255;255m"
black = "\033[38;2;0;0;0m"
red = "\033[38;2;255;0;0m"
green = "\033[38;2;0;255;0m"
blue = "\033[38;2;0;0;255m"
white_bg = "\033[48;2;255;255;255m"
black_bg = "\033[48;2;0;0;0m"
red_bg = "\033[48;2;255;0;0m"
green_bg = "\033[48;2;0;255;0m"
blue_bg = "\033[48;2;0;0;255m"

If you want more colors, W3Schools offers a free color picker.

Here is a template I made for RGB colors:


Yes, I think it’s easier too

Wow, this is much easier than the regular colour option! I can put in almost every colour now!

1 Like

I’m glad to see it helped!