曹耘豪的博客

Python在控制台输出彩色

  1. 直接上代码
  2. 参考

直接上代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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'

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

# or python3.6+
print(f"{bcolors.WARNING}Warning: No active frommets remain. Continue?{bcolors.ENDC}")

Windows可能需要先执行下os.system("color")

参考

   /