Home > Software design >  How do I add colour to text in python?
How do I add colour to text in python?

Time:07-27

I'm trying to turn certain letters in a word a different colour, and the word as a whole.

I've tried using termcolor and ANSI escape codes and they don't work.

I'm using IDLE as my IDE and Python 3 so this could be the reason? Does anyone have any solutions that work for these conditions?

CodePudding user response:

I'm using IDLE as my IDE and Python 3 so this could be the reason? Does anyone have any solutions that work for these conditions?

Yes, this is the reason. ANSI escape sequences only work on terminals, eg: CMD, Powershell, etc. Run your code using python3 file.py in the terminal and ANSI should work properly.

CodePudding user response:

hello there check this website for more colors https://ozzmaker.com/add-colour-to-text-in-python/ and the syntax is like this :
print("\033[1;32;40m Bright Green \n")

NOTE :
ANSI escape sequences work only if the code is run in a terminal window,

  • Related