Styling text in Python

Disclaimer: Python 3 only and console only

Using Colorama

one of the simplest ways I've found of colouring and styling my text in python is by using Colorama
import colorama
It has 3 different attributes
Fore - colour (of text)
Back - background
Style - things like Bold and italics

when styling code remember after styling the piece of text you must end the styling, to do this in colorama do `Style.RESET_ALL otherwise all your code will be that colour

with colorama to apply to text simply do

for more info read this

but there's so much you can do with 6 colours...

Using Termcolor

term colour is very similar to colorama in the styling except for the way you execute is slightly different

(i don't use term colour so I am not an expert, please correct me in comments)

for more info read this

Using Pure ANSI codes

finally no import required , just some base knowledge

Disclaimer i find it hard to read my text when it's with these codes so I put those codes in a separate variable and call them for readability

here's how to call

effectName = "\033[<effect><effect(could be corrosondant like with RGB)>m"
you can mix colours and effects so add as many <effects> as u need

here is a table of attributes/effects:

ANSI colours

ok styling is great but what we really want are cool colours, and the colours that give us are primitive
so to expand the spectrum we go to 4 bit colours!
(table explains it but I am better)

4-bit colours

from the above, we can make a yellow background with
ANother Disclaimer; these ANSI codes work in other languages but slightly different, I will try to make a tutorial in the future.

8-bit colours

Now this is more like it! 256 colours availible

using the able we can make navy like this:
\033[38;4;18m - the last one is the colour btw
\033[48;5;57m - another colour

i didn't mention it but you can mix colours too like this:


RGB colours

unlock the full-colour spectrum! now with RGB
here's how:
\033[38;2;<r>;<g>;<b>m #Select RGB foreground color
we can make a slick orange with:

final words

while termcolor and colorama are cool there selection is limited and once you have memorised that that table , you become a god of cool text

thanks for sticking around , if this helped then upvote

You are viewing a single comment. View All

Wow, Thank you @xolyon
Ur good!