Rey
Rey

Reputation: 1

How do I add colour to text in python?

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?

Upvotes: 0

Views: 114

Answers (1)

Naitik Mundra
Naitik Mundra

Reputation: 472

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.

Upvotes: 2

Related Questions