In this post we will be creating Python script that will change the background color of text in console using Colorama. Colorama is a Python library that simplifies the process of adding colors and styles to command-line output. It provides cross-platform support for colored terminal text, making it easier to enhance the visual appearance of terminal text. With Colorama, developers can easily make their terminal output more readable and visually appealing.
See the sample of Python code below where we use the Colorama library to change the background color of text.
The code uses the print()
function to output three different messages with different colors. Each message uses a different color from the Back
class in Colorama, followed by the text to print, and ends with Back.RESET
to reset the background text color to the default color.
The first message is printed in a red background , the second in a green background , and the third in a yellow background. Finally, the code calls time.sleep()
to pause execution for 10 seconds before exiting.
import colorama
from colorama import Back
import time
colorama.init()
print(Back.RED + 'This has a red background!' + Back.RESET)
print(Back.GREEN + 'This has a green background!' + Back.RESET)
print(Back.YELLOW + 'This has a yellow background!' + Back.RESET)
time.sleep(10)
See an image example below.

Take a look at some of our other content around the Python programming language by clicking here.