如何将彩色文本打印到终端 [英] How to print colored text to the terminal

查看:25
本文介绍了如何将彩色文本打印到终端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Python 中将彩色文本输出到终端?

How can I output colored text to the terminal in Python?

推荐答案

还有 Python termcolor 模块.用法很简单:

from termcolor import colored

print colored('hello', 'red'), colored('world', 'green')

或者在 Python 3 中:

Or in Python 3:

print(colored('hello', 'red'), colored('world', 'green'))

然而,对于游戏编程和彩色块"来说,它可能不够复杂.你想做的...

It may not be sophisticated enough, however, for game programming and the "colored blocks" that you want to do...

这篇关于如何将彩色文本打印到终端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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