在 Windows 10 上的 Python 3.7 上使用 Colorama

问题描述 投票:0回答:2

我正在尝试使用 colorama 将代码的一部分打印出来。我有:

from colorama import init, Fore, Style
init(convert=True)
print(Fore.RED + 'Hello')

但是代码输出没有颜色变化。我做错了什么?

python python-3.x
2个回答
0
投票

它无需 init(convert=True) 即可工作。你应该使用 init()

from colorama import init, Fore, Style
init()
print(Fore.RED + 'Hello')

0
投票

init() 的用法已经过时,不再推荐。

对于 Windows 10 及以上版本,请使用:

from colorama import just_fix_windows_console

just_fix_windows_console()

这个方法似乎也摆脱了使用通常与 init() 一起使用的参数“autoreset”和“convert”的需要

© www.soinside.com 2019 - 2024. All rights reserved.