Colors in cmd using Python?

Asked

Viewed 1,303 times

3

Guys I’m doing a game for college and I decided to put some colors in the code to look cute. I wanted to know how to make the colors of the strings appear in the cmd of windows. I tried to use the Ascii system but it didn’t work, below is a direct example of the code:

def menu():
print('\033[1;33mEntrando na configuração\033[1;33m')
select_rodadas()
select_player()

inserir a descrição da imagem aqui

The last two cmd lines should be yellow or orange. How do I make cmd recognize the colors?

1 answer

1

I recommend using the module Colorama.

Code example for Python 3:

from colorama import Fore, Style

print(f'{Fore.YELLOW}Entrando na configuracao{Style.RESET_ALL}')

Code example for Python 2:

from colorama import Fore, Style

print '{}Entrando na configuracao{}'.format(Fore.RED, Style.RESET_ALL)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.