If you’ve ever worked with some fany command-line tools, you might have seen some colored
text in there - maybe for a warning or error message or somesuch. It certainly can help
in reading comprehension in some situations, so how can we do it in Python?
Specifically, Python 3.8.5 on a Windows 10 machine.
Coloring Terminal Text in Python
The library that is recommended (especially for cross-platform use) is Colorama. This StackOverflow answer suggested its use.
Installing Colorama
Colorama didn’t come pre-installed, but pip saved me:
Coloring ‘print’ Statements Example
This Python 3 snippet will color text for you:
And it produces this output:
Eh… trust me. It’s colored. I cannot figure out how to get that to come through here, but it is I swear!
Coloring ‘input’ Statements Example
If you do something like this:
You do NOT get a red colored question prompt. You get gobbledy-gook at the front and end of the line, but no colors.