Python Forum
Adding colour to Python console
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding colour to Python console
#1
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.
Reply
#2
this will work if your terminal support ANSI code.
On windows - look at colorama, or termcolor (colorama is wrapper around termcolor)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
So I need an addon, right?
I hope it can work with Jupyter.
Reply
#4
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
(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,
newbieAuggie2019

"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python library for win32 console commands eldiener 3 247 Aug-24-2021, 10:28 PM
Last Post: bowlofred
  Problem: Restart kernel onPydev console when trying to install a python package poppy2020 1 2,254 Nov-25-2020, 06:13 PM
Last Post: Larz60+
  to call via console a python-programm Liki 9 1,024 Nov-22-2020, 01:10 AM
Last Post: bowlofred
  My Python Console doesn´t work ModuleNotFoundError: No module named 'tokenize' RuanKishibe 1 1,129 Aug-06-2020, 10:07 PM
Last Post: deanhystad
  how to get some values from js on python console by python code vivekagrey 1 758 Feb-13-2020, 09:26 PM
Last Post: micseydel
  I don't know what's wrong with this code [Python Console] H0M1C1D4L_P1G 6 1,274 Dec-22-2019, 10:27 PM
Last Post: snippsat
  Adding markers to Folium map only adding last element. tantony 0 920 Oct-16-2019, 03:28 PM
Last Post: tantony
  Keypress when running a python app in a console on windows Stephen 6 5,129 Apr-16-2019, 12:38 PM
Last Post: Stephen
  Is it possible to have my python shell change the backgrounds colour? OTO1012 2 1,757 Mar-07-2019, 09:32 PM
Last Post: woooee
  Printing arguments in python console. Narendra 1 947 Jan-28-2019, 12:00 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020