This somewhat depends on what platform you are on. The most common way to do this is by printing ANSI escape sequences. For a simple example, here's some Python code from the Blender build scripts:

class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKCYAN = '\033[96m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'

To use code like this, you can do something like:

print(bcolors.WARNING + "Warning: No active frommets remain. Continue?" + bcolors.ENDC)

Or, with Python 3.6+:

print(f"{bcolors.WARNING}Warning: No active frommets remain. Continue?{bcolors.ENDC}")

This will work on unixes including OS X, Linux and Windows (provided you use ANSICON, or in Windows 10 provided you enable VT100 emulation). There are ANSI codes for setting the color, moving the cursor, and more.

If you are going to get complicated with this (and it sounds like you are if you are writing a game), you should look into the "curses" module, which handles a lot of the complicated parts of this for you. The Python Curses HowTO is a good introduction.

If you are not using extended ASCII (i.e., not on a PC), you are stuck with the ASCII characters below 127, and '#' or '@' is probably your best bet for a block. If you can ensure your terminal is using a IBM extended ASCII character set, you have many more options. Characters 176, 177, 178 and 219 are the "block characters".

Some modern text-based programs, such as "Dwarf Fortress", emulate text mode in a graphical mode, and use images of the classic PC font. You can find some of these bitmaps that you can use on the Dwarf Fortress Wiki see (user-made tilesets).

The Text Mode Demo Contest has more resources for doing graphics in text mode.

Answer from joeld on Stack Overflow
Top answer
1 of 16
3044

This somewhat depends on what platform you are on. The most common way to do this is by printing ANSI escape sequences. For a simple example, here's some Python code from the Blender build scripts:

class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKCYAN = '\033[96m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'

To use code like this, you can do something like:

print(bcolors.WARNING + "Warning: No active frommets remain. Continue?" + bcolors.ENDC)

Or, with Python 3.6+:

print(f"{bcolors.WARNING}Warning: No active frommets remain. Continue?{bcolors.ENDC}")

This will work on unixes including OS X, Linux and Windows (provided you use ANSICON, or in Windows 10 provided you enable VT100 emulation). There are ANSI codes for setting the color, moving the cursor, and more.

If you are going to get complicated with this (and it sounds like you are if you are writing a game), you should look into the "curses" module, which handles a lot of the complicated parts of this for you. The Python Curses HowTO is a good introduction.

If you are not using extended ASCII (i.e., not on a PC), you are stuck with the ASCII characters below 127, and '#' or '@' is probably your best bet for a block. If you can ensure your terminal is using a IBM extended ASCII character set, you have many more options. Characters 176, 177, 178 and 219 are the "block characters".

Some modern text-based programs, such as "Dwarf Fortress", emulate text mode in a graphical mode, and use images of the classic PC font. You can find some of these bitmaps that you can use on the Dwarf Fortress Wiki see (user-made tilesets).

The Text Mode Demo Contest has more resources for doing graphics in text mode.

2 of 16
1220

There is also the Python termcolor module. Usage is pretty simple:

from termcolor import colored

print(colored('hello', 'red'), colored('world', 'green'))

It may not be sophisticated enough, however, for game programming and the "colored blocks" that you want to do...

To get the ANSI codes working on windows, first run

os.system('color')
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ print-colors-python-terminal
Print Colors in Python terminal - GeeksforGeeks
June 20, 2025 - The colorama module enables cross-platform support for printing colored text in the terminal using ANSI escape sequences. It works well on Windows (which doesnโ€™t support ANSI codes by default) and wraps the codes in a way that's consistent across OS.
Discussions

How to set python font color in terminal ?
Python does not control the colours of error messages - the terminal app does that. Check the documentation for your terminal application. Most terminals allow colours / themes to be configured, though unortunately the Windows terminal (cmd.exe) is rather limited in this respect. For using Python interactively (on Windows), iPython offers much more customisation. For running scripts, it may be time to start using a Python IDE. Thonny is a great option for beginners as it includes Python and is very easy to set up and start coding - just install the app and away you go. There are also more advanced IDE's, including PyCharm, vs-code, Wing, IDLE, and others, but they have a steeper learning curve. More on reddit.com
๐ŸŒ r/learnpython
14
0
April 19, 2025
colored printing in python
๐ŸŒ r/learnpython
5
9
February 8, 2022
A Python module for terminal colors.
This is my module, thanks i really didnt expected this to happen More on reddit.com
๐ŸŒ r/Python
12
25
July 23, 2023
How do I print colors in colorama using a hex?

https://en.wikipedia.org/wiki/ANSI_escape_code#Colors

More on reddit.com
๐ŸŒ r/learnpython
9
1
April 18, 2019
๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ python โ€บ print colored text to terminal with python
Print colored text to terminal with Python | Sentry
If we would prefer to abstract away from ANSI codes, we can use the termcolor library from PyPI. First, we must install it: ... We can then use the colored function from this library to print colored text.
๐ŸŒ
AskPython
askpython.com โ€บ python โ€บ examples โ€บ print-colored-text-to-the-terminal-in-python
Print Colored Text to the Terminal in Python - AskPython
February 23, 2023 - In this article we discuss some ... by printing the results in colored text. โ€œtermcolorโ€ is an ANSI escape sequence used for color formatting for output in the terminal....
๐ŸŒ
Medium
medium.com โ€บ @ryan_forrester_ โ€บ adding-color-to-python-terminal-output-a-complete-guide-147fcb1c335f
Adding Color to Python Terminal Output: A Complete Guide | by ryan | Medium
January 7, 2025 - The most direct way to add color in Python is using ANSI escape codes. These are special sequences that tell your terminal to change text colors:
๐ŸŒ
DEV Community
dev.to โ€บ dev_neil_a โ€บ python-how-to-adding-color-and-styles-to-terminal-text-3699
Python How-To: Adding Color And Style To Console Text - DEV Community
April 15, 2025 - There are also other options that can be used instead of bg and fg but for this guide, those were chosen. Next, three variables were defined to set the background & foreground (text_color), style (text_style) and lastly text_resetto reset the terminal back to it's default font style.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ how-to-print-colored-text-in-python
How to Print Colored Text in Python
February 27, 2023 - This can be done by appending \033[0;0m ... color scheme. This will provide the following output: Looks much better. Colorama is a Python package that provides methods to print colored text in Python....
Find elsewhere
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how to set python font color in terminal ?
r/learnpython on Reddit: How to set python font color in terminal ?
April 19, 2025 -

Hi,
When I run a python program that needs some debugging, the errors displayed on terminal screen mainly show up in some kind of reddish burgundy with low contrast with the black background when backlight is low.
Is there a way to set the font color to white or blue for all python output in terminal ?
Actually I have found a hack that is to pipe the output of the python command to a command that changes the ANSI color code emitted: python cmd.py |& change_color , but I'd prefer not to be compelled to use that if possible
Thanks for your help !

๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ examples โ€บ colored-terminal
Python Program to print colored text to the terminal
For more information regarding the ANSI escape code, you can refer to ANSI escape code. from termcolor import colored print(colored('Programiz', 'blue')) ... Using the module termcolor, you can get the desired output. Also, you can set different styles of the text using this module.
๐ŸŒ
PythonHow
pythonhow.com โ€บ how โ€บ print-coloured-text-on-the-terminal
Here is how to print coloured text on the terminal in Python
New: Practice Python, JavaScript ... on_color="on_white")) ... To print coloured text on the terminal in Python, you can use the colored() function from the termcolor package....
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ print colored text to the terminal in python
Print Colored Text to the Terminal in Python - Spark By {Examples}
May 31, 2024 - How to print colored text to the terminal in Python? There are several ways to print colored text to the terminal. Whether you want to use basic ANSI
๐ŸŒ
DEV Community
dev.to โ€บ muhimen123 โ€บ colored-text-in-terminal-using-python-1nmd
Colored text in terminal using Python - DEV Community
June 11, 2020 - In colorama, the font color or the text color is referred to as Fore(stands for foreground). To change the font color, start by importing the module. ... (For Windows only, you need to initialize colorama to output colors in the terminal, not ASCII escape sequence) Then, in the print statement, mention the color you want to use.
๐ŸŒ
Vultr
docs.vultr.com โ€บ python โ€บ examples โ€บ print colored text to the terminal
Python Program to print colored text to the terminal
December 26, 2024 - Use the following command: ... Import the colored function from the termcolor module. Apply the colored function to the text you wish to print, specifying the desired color as an argument.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Python Color Text to the Terminal / Output - YouTube
In this tutorial, we will have a look at how you can output text to the terminal using different colors. We will develop a little program to generate all the...
Published: August 24, 2021
๐ŸŒ
Towards Data Science
towardsdatascience.com โ€บ home โ€บ data science โ€บ how to print coloured text in the terminal using python
How To Print Coloured Text in The Terminal Using Python | Towards Data Science
August 17, 2022 - If you'd like to avoid the manual process of defining formatting and styling with the use of ANSI escape sequences you can instead take advantage of a third-party Python package called [Colorama](https://pypi.org/project/colorama/) which is available on PyPI. The package offers cross-platform text colouring which means that ANSI escape character sequences can work on MS Windows out of the box.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Add Text Color to Python Terminal Programs - YouTube
This how-to video shows you how to add colors and other text formatting to your command line (terminal) programs in Python.For the code used in this example,...
Published: March 21, 2022
๐ŸŒ
YouTube
youtube.com โ€บ watch
How to print coloured text on the terminal in Python - YouTube
AboutPressCopyrightContact usCreatorsAdvertiseDevelopersTermsPrivacyPolicy & SafetyHow YouTube worksTest new featuresNFL Sunday Ticket ยท ยฉ 2025 Google LLC
Published: November 30, 2024
๐ŸŒ
Medium
medium.com โ€บ ai-does-it-better โ€บ print-colored-text-in-python-enhance-terminal-output-b90aede058c8
Print Colored Text in Python โ€” Enhance Terminal Output
December 28, 2024 - Implement colorama for vibrant terminal texts, elevating data visualization for expert statisticians. # Demo program to showcase printing colored text in Python using colorama and termcolor libraries # Importing necessary libraries import colorama from colorama import Fore, Style from termcolor import colored colorama.init(autoreset=True) # Initializes colorama to autoreset colors after each print statement # Function to print colored text using colorama def print_with_colorama(): print(Fore.RED + 'This is red text using colorama') print(Fore.GREEN + 'This is green text using colorama') print(
๐ŸŒ
Medium
vascosim.medium.com โ€บ pythonic-aesthetics-enhancing-terminal-readability-with-color-52f6244e2e30
How to Print Colored Text in Python | Medium
January 23, 2024 - Here are some codes to get you started exploring, combining foreground and background color codes, and experimenting with different text formatting: ANSI escape code examples (Source: ANSI escape code โ€” Wikipedia) Now that weโ€™ve covered the fundamentals to terminal coloring, itโ€™s time to elevate your Python console printing game by exploring some popular third-party libraries.