_curses.error: add_wch() returned an error

僤鯓⒐⒋嵵緔 提交于 2019-12-02 00:53:52

That's expected behavior. Python uses ncurses, which does this because other implementations do this.

In the manual page for addch:

The addch, waddch, mvaddch and mvwaddch routines put the character ch into the given window at its current window position, which is then advanced. They are analogous to putchar in stdio(3). If the advance is at the right margin:

  • The cursor automatically wraps to the beginning of the next line.

  • At the bottom of the current scrolling region, and if scrollok is enabled, the scrolling region is scrolled up one line.

  • If scrollok is not enabled, writing a character at the lower right margin succeeds. However, an error is returned because it is not possible to wrap to a new line

Python's curses binding has scrollok. To add characters without scrolling, you would call it with a "false" parameter, e.g.,

self.main.scrollok(0)

If you do not want to scroll, you can use a try/catch block, like this:

import curses

def main(win):
  for y in range(curses.LINES):
    for x in range(curses.COLS):
      try:
        win.addch(y, x, ord('.'))
      except (curses.error):
        pass
      curses.napms(1)
      win.refresh()
  ch = win.getch()

curses.wrapper(main)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!