Python Forum
colorama/termcolor not returning coloured lines
Thread Rating:
  • 2 Vote(s) - 1.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
colorama/termcolor not returning coloured lines
#1
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
Reply
#2
where do you run this code? you need to run it from command prompt/terminal. I guess you run it in IDE...
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(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
Reply
#4
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 5,705 Aug-10-2020, 11:01 PM
Last Post: medatib531
  f-strings and termcolor newbieAuggie2019 6 11,511 Jul-28-2020, 02:50 AM
Last Post: santarosajoe
  Coloured text in the terminal works in Linux but not Windows Flexico 2 2,658 Aug-26-2019, 10:44 PM
Last Post: Flexico

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020