Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to print several sentences with different colors, but it won't work, I only got 2 colors, the normal blue and this red

import sys
from colorama import init, AnsiToWin32

stream = AnsiToWin32(sys.stderr).stream

print(">>> This is red.", file=stream)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
158 views
Welcome To Ask or Share your Answers For Others

1 Answer

As discussed in the comments, change your code to use these features;

import os, colorama
from colorama import Fore,Style,Back
colorama.init()

print(Fore.RED + 'some red text')
print(Back.GREEN + 'and with a green background')
print(Style.BRIGHT + 'and in bright text')
print(Style.RESET_ALL)
print('back to normal now')

These are much easier to use and do job. The available colours you can use for Fore or Back are;

  • Red
  • Cyan
  • Green
  • Yellow
  • Black
  • Magenta
  • Blue
  • White

These will all be needed to be put in capitals. And for Style you can use;

  • Bright
  • Dim
  • Reset_all

These will also need to be in capitals.

Have fun using colorama :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...