0

I tryed everything I found on internet about print with color on python 3.7 on console, but nothing actualy worked. The last thing that I tried was just put the color codes as I see that many people do that.

a='\033[1;31;42m' + "Wellcome to my quiz!" + '\033[0m'
print(a)

But when I try to do it gives me this at output on console:

[1;31;42mWellcome to my quiz![0m

I tryed this too:

class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'
print bcolors.GREEN + "Wellcome" + bcolors.ENDC

And Gave me this error: "SyntaxError: Missing parentheses in call to print." But when I put the parentheses like this:

print (bcolors.GREEN + "Wellcome to my quiz" + bcolors.ENDC)

The output is similar to the first attempt that I shown:

[92mWellcome to my quiz![0m

Am I doing this wrong or this just doesn't work for me?
Platform: Windows 10 64bit.
Using Python 3.7.4 32bit from https://www.python.org/
Software: PyCharm or IDLE(Default python editor)(most used: IDLE)

PS: I don't wanted to use IDLE to reproduce the colors, I wanted the python terminal/console when we open normally a python file.

*Edit: I'm using the console that came when I installed Python3.7 with IDLE. I'm a beginner.

  • 1
    You need to know what kind of console you have, and what termcaps it supports. Either the console has been configured with no colour, or termcaps is not set correctly or set at all. – Gem Taylor Nov 08 '19 at 17:26
  • 1
    What about using the `termcolor` module? As seen in [this answer](https://stackoverflow.com/a/293633/9221467) – SRT HellKitty Nov 08 '19 at 17:26
  • 1
    If you're getting that output, your console doesn't support ANSII escape codes (that's what the `'\033[1;31;42m'` bit is). – Carcigenicate Nov 08 '19 at 17:34
  • SRT HellKitty I tryed that too, same output. Carcigenicate what consoles can I use to get the color printed as actual colors.? – Edgar Tavares Nov 08 '19 at 17:37
  • 1
    So you need to tell us something about your setup? What platform, what tty software, etc? – Gem Taylor Nov 08 '19 at 18:45
  • 1
    Possible duplicate of [How do I print colored text in IDLE's terminal?](https://stackoverflow.com/questions/42472958/how-do-i-print-colored-text-in-idles-terminal) – Gino Mempin Nov 08 '19 at 23:13

1 Answers1

0

I had same problem when I was working with terminal like cmd output so I solve my problem with colorama https://pypi.org/project/colorama/

KmcASI
  • 76
  • 6
  • That doesn't for me too... when I try to open the file with the python console it just closes at the same time. I'm just using PyCharm anyway for this project from here, for me the way that I shown on the question just works on PyCharm terminal for me. Why? I don't know... – Edgar Tavares Nov 09 '19 at 20:38
  • on pycharm will not show correct colors, u need to open it manual and will show u the CMD like console – KmcASI Nov 10 '19 at 19:09