2

Using ANSI escape sequence, I can change the color of text that python prints. The example below prints "Hi World" in light blue.

#!/usr/bin/python3
print(f'\033[38;5;117mHi World')

While this works I am limited to just 256 colors. Are there any terminals or extensions that allow me to print colors in hex triplets #000000-#FFFFFF using python?

un31389
  • 21
  • 2

1 Answers1

3

Yes, there are, but not all terminals support it, some do it differently than others, you need to figure out what your terminal's capabilities are... In other words: it's possible, but you don't want to do it yourself.

The standard way of doing it is hence using a library, in the Python casr that would probably be Rich or Textual, depending on whether you just want pretty colorful text or also prompts, buttons, tables etc.

Marcus Müller
  • 21,602
  • 2
  • 39
  • 54