Search code examples
pythoncurses

Change the attributes of a character at a certain y,x location with python curses


Lets say that the text "hello world" is printed out like so to a curses screen:

stdscr.addstr(0, 0, "hello world")

Now, lets say that I wanted the letter 'e' (y,x position 1,0) to have the attribute A_BOLD or A_REVERSE. How could I do this? Is there a function that just changes the attributes at a certain y,x position? I am using Python3.6 with curses (obviously)

EDIT: I tried using chgat, but it is not working as it should be. I used it like so:

stdscr.chgat(0, 1, curses.A_BOLD)

But this makes every single character after the x position has the attribute applied. I want only the character at the y,x position to be affected.


Solution

  • The Python curses wrapper has several variations of chgat with different parameter lists. The one you should use is window.chgat(y, x, num, attr)

    If you want to move back to a given location, you would save the current location (which you obtain by getyx, and then do a move to the saved location.