pythonconsole-applicationrich

Set the background of python console to an rgb value?


I'm working on a little side project console-based python script. I'm using a module called rich to add colours but i was wondering if you could also set the background colour as well.

I know the color command exists but it's very limited. Any help would be appreciated!


Solution

  • This will change the background to yellow on supported consoles:

    print("\033]11;#ffff00\007")
    

    The pattern is: "\033]11;#rrggbb\007", where rr, gg and bb are the red, green and blue values in hexadecimal ranging from 0x00 to 0xFF.