python colorama模块

colorama是一个python专门用来在控制台、命令行输出彩色文字的模块,可以跨平台使用。

1. 安装colorama模块

1

pip install colorama

  

可用格式常数:

1

2

3

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

  

跨平台印刷彩色文本可以使用彩色光的常数简称ANSI转义序列:

1

2

3

4

5

6

fromcoloramaimportFore,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关键字参数:

init()接受一些* * kwargs覆盖缺省行为

1

init(autoreset=False):

  

如果你发现自己一再发送重置序列结束时关闭颜色变化每一个打印,然后init(autoreset = True)将自动化

示例:

1

2

3

4

fromcoloramaimportinit,Fore

init(autoreset=True)

print(Fore.RED+"welcome to python !!")

print("automatically back to default color again")

colorama是一个python专门用来在控制台、命令行输出彩色文字的模块,可以跨平台使用。

1. 安装colorama模块

1

pip install colorama

  

可用格式常数:

1

2

3

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

  

跨平台印刷彩色文本可以使用彩色光的常数简称ANSI转义序列:

1

2

3

4

5

6

fromcoloramaimportFore,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关键字参数:

init()接受一些* * kwargs覆盖缺省行为

1

init(autoreset=False):

  

如果你发现自己一再发送重置序列结束时关闭颜色变化每一个打印,然后init(autoreset = True)将自动化

示例:

1

2

3

4

fromcoloramaimportinit,Fore

init(autoreset=True)

print(Fore.RED+"welcome to python !!")

print("automatically back to default color again")