colorama 彩色文字
实例
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')
Style.RESET_ALL
重置字体,背景和明暗度;
常用的颜色
字体色(Fore)/背景色(Back): BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET
Style: DIM, NORMAL, BRIGHT, RESET_ALL
使用ANSI序列指定颜色
print('\033[31m' + 'some red text')
print('\033[30m') # and reset to default color
在Windows下,需要先调用init();
可以和ANSI库,如Termcolor连用:
from colorama import init
from termcolor import colored
# 使用Colorama,确保Termcolor可以在windows下使用
# 自动重置,颜色定义只生效一次
init(autoreset=True)
# 使用Termcolor,给所有文本加上颜色
print(colored('Hello, World!', 'green', 'on_red'))