Python Curses Handling Window (Terminal) Resize

Pez Cuckow picture Pez Cuckow · Mar 2, 2011 · Viewed 21.3k times · Source

This is two questions really:

  • how do I resize a curses window, and
  • how do I deal with a terminal resize in curses?

Is it possible to know when a window has changed size?

I really can't find any good doc, not even covered on http://docs.python.org/library/curses.html

Answer

Michael McLoughlin picture Michael McLoughlin · Mar 4, 2011

Terminal resize event will result in the curses.KEY_RESIZE key code. Therefore you can handle terminal resize as part of a standard main loop in a curses program, waiting for input with getch.