用不同的颜色打印几个句子 [英] Print several sentences with different colors

查看:87
本文介绍了用不同的颜色打印几个句子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用不同的颜色打印几个句子,但是它不起作用,我只有两种颜色,普通的蓝色和红色

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)

推荐答案

如注释中所述,更改您的代码以使用这些功能;

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')

这些更加易于使用和执行.可以用于ForeBack的可用颜色是;

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

  • 红色
  • 青色
  • 绿色
  • 黄色
  • 黑色
  • 洋红色
  • 蓝色
  • 白色

所有这些都需要放在大写字母中. 对于Style,您可以使用;

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

  • 明亮
  • 昏暗
  • 全部重置

这些也必须在大写字母中.

These will also need to be in capitals.

使用colorama获得乐趣:)

Have fun using colorama :)

这篇关于用不同的颜色打印几个句子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆