好吧,我正在使用 Colorama for Python,我正在制作一个基于文本的角色扮演游戏。我需要使用这些颜色有很多原因,我猜主要是因为元素“稀有”。有没有一种方法可以不必每次打印彩色文本时都重置 Fore/Style?我在 Windows 10 上。
我想举个例子
print(Fore.GREEN + "Welcome to my shop, here are my items...")
print("Generic item 1...")
但我不想让第二条打印线变成绿色,而不是每次都重置它。
最佳答案
来自 colorama 包 website ,
If you find yourself repeatedly sending reset sequences to turn off color changes at the end of every print, then init(autoreset=True) will automate that:
from colorama import init
init(autoreset=True)
print(Fore.RED + 'some red text')
print('automatically back to default color again')
https://stackoverflow.com/questions/43649051/