Python Forum
Adding colour to Python console - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Adding colour to Python console (/thread-25746.html)



Adding colour to Python console - Archangelos - Apr-10-2020

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.


RE: Adding colour to Python console - buran - Apr-10-2020

this will work if your terminal support ANSI code.
On windows - look at colorama, or termcolor (colorama is wrapper around termcolor)


RE: Adding colour to Python console - Archangelos - Apr-10-2020

So I need an addon, right?
I hope it can work with Jupyter.


RE: Adding colour to Python console - buran - Apr-10-2020

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


RE: Adding colour to Python console - newbieAuggie2019 - Apr-15-2020

(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,