Search code examples
pythonrefreshncursescurses

How to refresh curses window correctly?


while 1:
    ...
    window.addstr(0, 0, 'abcd')
    window.refresh()
    ...

window size is full terminal size, big enough to hold abcd. If 'abcd' is modified to shorter string like 'xyz', then on terminal I will see 'xyzd'. What exactly I am doing wrong?


Solution

  • addstr() only prints the string you specify, it does not clear the following characters. You will have to do that yourself:

    • To clear characters until the end of the line, use clrtoeol(),

    • To clear characters until the end of the window, use clrtobot().