Skip to content » Python Unit Home » Python Console Colors

Python Console Colors


How to add colored text and background to your Python Programs

In this video tutorial you will learn how to add colors to your Python programs. You can install 3rd party modules like colorama, but sometimes it’s better if you just write your own!

Video Tutorial

Youtube blocked in your school? Here’s the Google Drive Link instead.

Full Code

Full Code

import os

os.system("cls") #use this for windows. change to os.system("clear") for linux

"red": "\u001b[31;1m",
"cyan": "\u001b[36m",
#You can add more colors and backgrounds to the dictionary if you like.

def colorText(text):
    for color in COLORS:
        text = text.replace("[[" + color + "]]", COLORS[color])
    return text

#Example printing out some text
hello = "[[red]]hello [[blue]]world[[white]]"

#Example printing out an ASCII file
f  = open("pythonlogo2.txt","r")
ascii = "".join(f.readlines())