Colours in Windows cmd with Python

时间:2018-12-04 18:28:56

标签: python cmd colors

I am trying to get colours to work in Python using windows cmd but it is not working. I've tried a few packages, but they all result in something similar.

At the moment, my code looks like this:

from colors import *

print(color('some text', fg='rgb(255, 0, 0)'))

However, this just prints [38;2;255;0;0msome text[0m into the console in white.

What am I doing wrong here?

EDIT: I am using this package

EDIT2:我需要打印许多不同的精确RGB值。

EDIT3:以下代码适用于colorama,但是afaik colorama不允许您指定确切的RGB值。

from colorama import init, Fore, Back, Style

init(convert=True)

print(Fore.RED + 'some red text')

1 个答案:

答案 0 :(得分:1)

Re-enable ANSI console color for Windows 10.16257 and later:运行

config.ini

重新启动Windows命令提示符(reg add HKCU\Console /v VirtualTerminalLevel /t REG_DWORD /d 1 )。