I have the piece of code below which wouldn't work unless n_rows > 3
or n_cols > 3
. Otherwise I get this error:
Traceback (most recent call last):
File "script.py", line 16, in <module>
curses.wrapper(main)
File "/usr/lib/python3.8/curses/__init__.py", line 105, in wrapper
return func(stdscr, *args, **kwds)
File "script.py", line 10, in main
window.addstr(2, 2, '2')
_curses.error: addwstr() returned ERR
This type of error normally happens when printing outside window (which isn't the case here).
def main(stdscr):
n_rows = 3
n_cols = 3
window = stdscr.subwin(n_rows, n_cols, 0, 0)
window.addstr(0, 0, '0')
window.addstr(1, 1, '1')
window.addstr(2, 2, '2')
stdscr.getch()
if __name__ == '__main__':
curses.wrapper(main)
My question is what explains the necessity for window to be one size larger for it to work?