# 使用colorama显示文本颜色

 1 #使用colorama显示文本颜色
 2 
 3 from colorama import init, Fore, Back, Style
 4 init()        # 初始化
 5 
 6 print(Fore.RED + "  错误信息  " + Style.RESET_ALL)
 7 print(Back.RED + "  错误信息  " + Style.RESET_ALL + '\n')
 8 
 9 print(Fore.BLUE + Back.RED + "  红色信息  " + Style.RESET_ALL )
10 print(Fore.BLUE + Back.RED + "  红色信息  " + Style.RESET_ALL + '\n')
11 print(Fore.BLUE + Back.YELLOW + "  黄色信息  " + Style.RESET_ALL)
12 print(Fore.BLUE + Back.YELLOW + "  黄色信息  " + Style.RESET_ALL + '\n')
13 print(Fore.BLUE + Back.GREEN + "  绿色标题  " + Style.RESET_ALL)
14 print(Fore.BLUE + Back.GREEN + "  绿色标题  " + Style.RESET_ALL + '\n')
15 
16 #1. 初始化
17 from colorama import Fore, Back, Style, init
18 init()  # 初始化colorama(Windows下必需)
19 
20 # 前景色(文字颜色)
21 print(Fore.RED + "红色文字")
22 print(Fore.GREEN + "绿色文字")
23 print(Fore.BLUE + "蓝色文字")
24 
25 # 背景色
26 print(Style.RESET_ALL + "重置所有样式")  # 恢复默认
27 print(Back.YELLOW + "黄色背景文字")
28 print(Back.CYAN + "青色背景文字")
29 
30 # 样式
31 print(Style.BRIGHT + "亮色文字" + Style.RESET_ALL)
32 print(Style.DIM + "暗色文字" + Style.RESET_ALL)
33 print(Style.NORMAL + "正常文字" + Style.RESET_ALL)
34 print(Style.RESET_ALL + "重置所有样式")  # 恢复默认

 

posted @ 2025-06-16 09:42  nxhujiee  阅读(23)  评论(0)    收藏  举报