Python Forum

Full Version: colorama/termcolor not returning coloured lines
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code -
from colorama import Fore, Back, Style
print(Fore.RED + 'some red text')
print(Back.GREEN + 'and with a green background')
print(Style.DIM + 'and in dim text')
print(Style.RESET_ALL)
print('back to normal now')
output -
Output:
[31msome red text [42mand with a green background [2mand in dim text[0m back to normal now
I used colorama library to change the font colour of few words. Unfortunately, it is not returning any lines with their respective colors. Can anyone help me to identify the issue?. Thanks in advance
where do you run this code? you need to run it from command prompt/terminal. I guess you run it in IDE...
(Jan-14-2019, 12:43 PM)buran Wrote: [ -> ]where do you run this code? you need to run it from command prompt/terminal. I guess you run it in IDE...
I did run it in IDLE. I also ran it in command prompt/terminal and it is still giving the same output. I read somewhere that my PC color codes has to match with python color codes and something to do with ANSI color code mismatch. Do you know anything about that?
Thank you
On windows you need to call init(). On other platforms it's simply ignored if present

from colorama import Fore, Back, Style, init
init()
print(Fore.RED + 'some red text')
print(Back.GREEN + 'and with a green background')
print(Style.DIM + 'and in dim text')
print(Style.RESET_ALL)
print('back to normal now')
run this from cmd, not in IDLE