Question

Why is this piece of python code not producing a normal black background color?

import curses

def func(stdscr):      
    c = stdscr.getkey()
curses.wrapper(func)   

I really don't get it. I played around with many things (color_pair, pair_number, init_pair, etc). This is really not black.

I'm using the default ubuntu gnome-terminal. (But afaik it doesn't make a difference).

curses - not black

Was it helpful?

Solution

Unless you manually specify the colors, curses is going to respect your terminals color palette. Most terminals will use your settings from a .Xresources or .Xdefaults file (not sure about gnome-terminal)

However if you want to manually define your colors. Use curses.init_color, this doesn't work on all terminals, more info on its usage in the python curses documentation. Do remember to reset the colors before quitting (curses.wrapper should do this for you).

def func(stdscr):
    if curses.can_change_color():
        # init_color(n, r, g, b)
        # n=0 is background
        curses.init_color(0, 0, 0, 0)
    c = stdscr.getkey()

OTHER TIPS

In gnome-terminal there's a setting called Palette. It can be found under `Edit Profile -> Colors. This palette setting only applies to terminal applications.

Therefore the other settings (foreground / background colors) in the same dialog, are useless for applications.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top