Outputting to the Terminal in Colors – With Python!!

So, recently I’ve been working on a Virtual Pet Game in Python (https://github.com/lunacodes/pypet).  It’s terminal/command line based right now, and I needed a way for it to stand out & not just look like an endless blob of terminal tests.  I had seen a talk of Tom Ballinger’s about Outputting Colors to the Terminal, and after a bit of Research, I found Colorama.

Colorama is wonderful in that it’s Cross-Platform, and Exceedingly Simple to use!!

The gyst is:

from colorama import init
init()
from colorama import Fore, Back, Style
print(Fore.RED + 'some red text')
print(Back.GREEN + 'and with a green background')
print(Style.DIM + 'and in dim text')
print(Fore.RESET + Back.RESET + Style.RESET_ALL)
print('back to normal now')

You can also use ANSI Codes or existing ANSI Libraries (such as Termcolor)

It’s such a fun & easy way to add a Colorful & Nice touch to your Terminal Programs 🙂

Advertisements
Outputting to the Terminal in Colors – With Python!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s