0

I have a simple code (not using GUI or other complex stuff, just basic code) in python 3 that receives an input from the user. However, I wish the input that gets written on the console to be colored, just as if we used colored from termcolor for the output.

How can I achieve this in a simple way?

EDIT: (See Pic) I want 'This text' that I wrote in the console as input to be colored.

There you have an example

Community
  • 1
  • 1
Leonard V.
  • 115
  • 1
  • 8
  • 1
    Does this answer your question? [How to print colored text in terminal in Python?](https://stackoverflow.com/questions/287871/how-to-print-colored-text-in-terminal-in-python) – mrzo Mar 08 '20 at 19:48
  • no, it does not. I have something like: **x = input('This text') and I want to 'This text' to be colored in the console when I write it, EDIT: See initial post, I made an update – Leonard V. Mar 08 '20 at 19:56
  • Ah, okay. On which OS? – mrzo Mar 08 '20 at 20:00
  • Windows 10. Check the picture, in case there is unclear info – Leonard V. Mar 08 '20 at 20:01
  • It would require interacting with the DOS CLI. While it is possible to change the default color via command line ( https://www.computerhope.com/color.htm ), I highly doubt you can do it from Python (it would be a serious potential security flaw) – Sam Mar 08 '20 at 20:05

1 Answers1

0
from colorama import Fore, init
init()
x = input(f"This is {Fore.GREEN}green: {Fore.RED}")
print(f"{Fore.WHITE}Back to white")
Błotosmętek
  • 12,717
  • 19
  • 29