Reputation: 61
Okay so I'm using Colorama for Python, and I'm making a text based RPG. I need to use the colors for many reasons, mainly for item "rarity" I guess. Is there a way to not have to reset the Fore/Style every single time I print colored text? I'm on Windows 10.
I guess an example would be
print(Fore.GREEN + "Welcome to my shop, here are my items...")
print("Generic item 1...")
But I don't want to have that second printed line be green, WITHOUT resetting it every time.
Upvotes: 5
Views: 7657
Reputation: 532
From the colorama package 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')
Upvotes: 10
Reputation: 3635
Once you have changed the color of your output text it cannot go back to normal without actually resetting it back to normal.
So to further on from MK Ultra's comment I would suggest something like this;
def print_normal(string): #takes your string as input
print(Fore.WHITE+Style.RESET_ALL+string)
#prints normal color and style text to the console
So then in your example code;
print(Fore.GREEN + "Welcome to my shop, here are my items...") #green text
print_normal("Generic item 1...") #normal text
Upvotes: 3