-1

Hello so I am using Python and I want to print out the name of the program with color while using figlet_format so I got it working fine in vscode but when I try to run the file in cmd it prints this:

[34m _   _      _ _
| | | | ___| | | ___
| |_| |/ _ \ | |/ _ \
|  _  |  __/ | | (_) |
|_| |_|\___|_|_|\___/

[0m

insted of printing what it prints in vscode:

enter image description here

So I was wondering if there is a way to print color in cmd while using pyfiglet, this is my code:

from termcolor import colored
from pyfiglet import figlet_format

print((colored(figlet_format("Hello"), color="blue")))
retryoos
  • 3
  • 1
  • 4
  • Duplicate of [Python: How can I make the ANSI escape codes to work also in Windows?](https://stackoverflow.com/questions/12492810/python-how-can-i-make-the-ansi-escape-codes-to-work-also-in-windows) – Jongware Apr 12 '20 at 15:43

2 Answers2

1

You can also try this new library Printy Just released version 1.2.0 as a cross-platform library.

Check it out: Printy on github

It is based on flags so you can do stuff like

from printy import printy

# with global flags, this will apply a bold (B) red (r) color and an underline (U) to the whole text
printy("Hello world", "rBU")

# with inline formats, this will apply a dim(D)
#blue (b) to the word 'Hello' and a striked (S)
#yellow (y) to the word 'world', the rest will remain as the predefined format
printy("this is a [bD]Hello@ [yS]world@ text")

enter image description here

0

On Windows, you need to install Colorama.

Makes ANSI escape character sequences (for producing colored terminal text and cursor positioning) work under MS Windows.

Laurent LAPORTE
  • 21,958
  • 6
  • 58
  • 103