Printing Colored Text in Python Without Any Module
by Megacapacitor in Circuits > Software
58885 Views, 0 Favorites, 0 Comments
Printing Colored Text in Python Without Any Module
![Screenshot at 2018-07-25 13-02-33.png](/proxy/?url=https://content.instructables.com/FLW/6E64/JJZN6RL0/FLW6E64JJZN6RL0.png&filename=Screenshot at 2018-07-25 13-02-33.png)
After my second Instructable was deleted accidentally, I decided to make a new one.
In this one I will show you how to print colored text in python!
The Codes
Try:
TGREEN = '\033[32m' # Green Text print (TGREEN + "This is some green text!")
We see that after the green text is printed, the whole shell changes color!
To combat that can we use this?
TWHITE = '\033[37m' print (TGREEN + "It doens't reset!" , TWHITE)
NO!!
It turns all the text white...and a different type of 'dull' white if you see it carefully.
If you want to commit your code to GITHUB, then many people using your code may have a customized Python Shell with probably YELLOW or Something as their text/background color!
So the answer is:
ENDC = '\033[m' # reset to the defaults print (TGREEN + "Das ist es!" , ENDC)
Usage
![Screenshot at 2018-07-25 13-10-56.png](/proxy/?url=https://content.instructables.com/FDV/UAIV/JJZN6S5Y/FDVUAIVJJZN6S5Y.png&filename=Screenshot at 2018-07-25 13-10-56.png)
List of Codes
![ANSI-use.png](/proxy/?url=https://content.instructables.com/FM6/JGYQ/JJZN6S3E/FM6JGYQJJZN6S3E.png&filename=ANSI-use.png)