Python Forum

Full Version: Adding colour to Python console
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello guys,

I tried to colourise the texts in a Python consol applications but the results were a little bit weird.

Firstly, I googled the whole thing and I discovered the ANSI codes. For example, take a look at the following code.

print("\033[0;37;40m Normal text\n")
print("\033[2;37;40m Underlined text\033[0;37;40m \n")
print("\033[1;37;40m Bright Colour\033[0;37;40m \n")
print("\033[3;37;40m Negative Colour\033[0;37;40m \n")
print("\033[5;37;40m Negative Colour\033[0;37;40m\n")
This code is not part of my project, just to let you know what I did. I utlised these stuff in my code but the console remained with black background and white (or light grey) font colour. The funny thing is that in the Jupyter window the ANSI colour codes did work.
this will work if your terminal support ANSI code.
On windows - look at colorama, or termcolor (colorama is wrapper around termcolor)
So I need an addon, right?
I hope it can work with Jupyter.
it's a package. Like any other package in python. I don't use Jupyter, so someone else would tell. There might be other solutions in Jupyter
(Apr-10-2020, 12:57 PM)Archangelos Wrote: [ -> ]Hello guys,

I tried to colourise the texts in a Python consol applications but the results were a little bit weird.
Hi!

Maybe this can give you some ideas:

https://python-forum.io/Thread-colouring-strings

I hope it helps.

All the best,