-2

Original: os.system("echo \u001b[31mU have Been Hacked").

And I have tried print(u""), print() but nothing works and I don't want to install any libraries so can someone help me?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61

2 Answers2

0

Use colorama library.

import colorama

# Init allows color printing on windows terminals
# and autoreset resets to default color after each print
colorama.init(autoreset=True)

print(colorama.Fore.Green + "Hello world!")
sqz
  • 317
  • 5
  • 12
  • *i dont want to install any libaries*... – Tomerikoo Aug 16 '20 at 15:37
  • I don't think there is an easy way to print colors on windows terminals without the colorama library. Unless you are strictly targeting [windows 10](https://stackoverflow.com/questions/16755142/how-to-make-win32-console-recognize-ansi-vt100-escape-sequences) – sqz Aug 16 '20 at 15:51
0

So this is without installing any libraries my implementation is

import os


def printWhiteOnRed(s):
    os.system("echo |set /p out=\u001b[97;101m")
    print(s)
    os.system("echo |set /p out=\u001b[0m")

s= "you have done well"
printWhiteOnRed(s)

|set /p out=
This is to supress line ending in the command prompt, see this Stack Overflow answer.

\u001b
This is the ANSI escape character

[97;101m This are the colours for white foreground on red background.

[0m This is the reset code to ensure any further output is in normal style

Sources: Stackoverflow github

Catalina Chircu
  • 1,506
  • 2
  • 8
  • 19
Gautamrk
  • 1,144
  • 9
  • 12