在Python中,我们可以使用Colorama库来实现不同颜色和风格的字体输出。以下是一个示例代码,展示了如何在控制台中输出不同颜色和风格的字体
示例代码
from colorama import init, Fore, Back, Style
# 初始化Colorama模块
init(autoreset=True)
# 不同颜色的字体输出
print(Fore.RED + '红色字体')
print(Fore.GREEN + '绿色字体')
print(Fore.YELLOW + '黄色字体')
print(Fore.BLUE + '蓝色字体')
print(Fore.MAGENTA + '洋红色字体')
print(Fore.CYAN + '青色字体')
print(Fore.WHITE + '白色字体')
# 不同背景色的字体输出
print(Back.RED + '红色背景色')
print(Back.GREEN + '绿色背景色')
print(Back.YELLOW + '黄色背景色')
print(Back.BLUE + '蓝色背景色')
print(Back.MAGENTA + '洋红色背景色')
print(Back.CYAN + '青色背景色')
print(Back.WHITE + '白色背景色')
# 不同字体风格的输出
print(Style.BRIGHT + '加粗字体')
print(Style.DIM + '暗淡字体')
print(Style.NORMAL + '正常字体')
print(Style.RESET_ALL) # 重置字体样式