bluethundr
bluethundr

Reputation: 1325

Change Color Output in Python in windows

I'm trying to change the output text to green and the background to blue using this code:

print("\033[1;32;44m******************************************************\n")
print("\033[1;32;44m* Terminate Instance Operations in AWS Are Complete. *\n")
print("\033[1;32;44m******************************************************\n")

But the output is the the default powershell white and the numeric codes are visible. This is how the output looks:

[1;32;44m******************************************************

[1;32;44m* Terminate Instance Operations in AWS Are Complete. *

[1;32;44m******************************************************

I'm running the script on win 10 currently. What am I doing wrong?

Upvotes: 2

Views: 4488

Answers (2)

user26571104
user26571104

Reputation: 1

you can use termcolor: pip install termcolor

then:

from termcolor import colored

print(colored(<text>, <color>))

Upvotes: 0

Maximilian Burszley
Maximilian Burszley

Reputation: 19654

Depending on your version of Windows 10, your console host may not support VTY emulation which enables you to use those escape sequences. You can work around this as such:

import os

os.system('COLOR 12')

See cmd.exe /c COLOR /? for more.


To see if your console has the support, enter this command in PowerShell:

$Host.UI.SupportsVirtualTerminal

Upvotes: 4

Related Questions