更改python shell中文本的颜色?

2024-05-03 23:12:44 发布

您现在位置:Python中文网/ 问答频道 /正文


Tags: python
2条回答

请看一下问题的答案:

如果无法安装附加模块,可以尝试使用 直接使用ANSI序列。请注意,该方法不可移植, 最好使用一些特殊的模块。

print " "+ "\033[01;41m" + " " +"\033[01;46m" + " " + "\033[01;42m"

当您需要更强大的功能时,我建议您使用colorama(pypi.python.org/pypi/colorama):

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

另一个选项,使用termcolor

from termcolor import colored
print colored('hello', 'red'), colored('world', 'green')

相关问题 更多 >