Colorama is a python-specific module for outputting color text in the console and command line, and can be used across platforms.
1. Installing the Colorama module
Available Format constants:
123 |
Fore: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET. Back: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET. Style: DIM, NORMAL, BRIGHT, RESET_ALL |
Cross-platform printing color text can use the constant abbreviation ANSI escape sequence of colored light:
123456 |
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
(Style.RESET_ALL)
print
(
"back to normal now!!"
)
|
init keyword parameter:
Init () accepts some * * Kwargs override default behavior
1 |
init(autoreset = False ): |
If you find yourself repeatedly sending reset sequences at the end of the turn off color changes every print, then init (Autoreset = True) will be automated
Example:
1234 |
from colorama import init,Fore init(autoreset = True ) print (Fore.RED + "welcome to python !!" ) print ( "automatically back to default color again" ) |
Python Colorama module