[英]_curses.error: addwstr() returned ERR on changing nlines to 1 on newwin method
The code is: 代码是:
from curses import *
from curses.panel import *
def main(stdscr):
start_color()
curs_set(0)
init_pair(1, COLOR_BLACK, COLOR_CYAN)
posy = posx = 0
window = newwin(1, 1, posy, posx)
panel = new_panel(window)
window.addstr('*', color_pair(1))
update_panels()
doupdate()
while True:
key = stdscr.getch()
if key == ord('j'):
posy+=1
elif key == ord('k'):
posy-=1
elif key == ord('h'):
posx-=1
elif key == ord('l'):
posx+=1
elif key == ord('q'):
endwin()
break
panel.move(posy,posx)
update_panels()
doupdate()
if __name__ == '__main__':
wrapper(main)
I am getting this error: 我收到此错误:
Traceback (most recent call last):
File "test_1_height_error.py", line 34, in <module>
wrapper(main)
File "/usr/lib/python3.7/curses/__init__.py", line 94, in wrapper
return func(stdscr, *args, **kwds)
File "test_1_height_error.py", line 12, in main
window.addstr('*', color_pair(1))
_curses.error: addwstr() returned ERR
However if I change line 10 from window = newwin(1, 1, posy, posx) to window = newwin(2, 1, posy, posx) ie change the nlines args to greater than 1 then it works fine. 但是,如果我将第10行从window = newwin(1,1,posy,posx)更改为window = newwin(2,1,posy,posx),即将nlines args更改为大于1,那么它将正常工作。
I really don't understand why I am getting this issue. 我真的不明白为什么会遇到这个问题。
addch
and anything built from it (such as addstr
) prints the text and advances the cursor past what was printed. addch
和从中构建的所有内容(例如addstr
)都会打印文本, 并将光标移到所打印的内容之外。
A 1x1 window isn't big enough to write one character and wrap to the next line (since you filled the line). 1x1窗口不足以写一个字符并换行到下一行(因为您已填满该行)。 When the window was 2x1 , it could do that.
当窗口为2x1时 ,它可以做到。
ncurses (any X/Open Curses) has other functions (such as addchstr
) that don't advance the cursor, but I don't see those mentioned in the python curses reference . ncurses(任何X / Open Curses)具有其他功能(例如
addchstr
),这些功能不会使光标前进,但是我看不到python curses参考中提到的那些功能。
Since ncurses will print the character that you want, and it's an isolated case, the workaround is to wrap the addstr in a try-statement, eg, 由于ncurses会打印您想要的字符,并且这是一个孤立的情况,因此解决方法是将addstr包装在try语句中,例如,
try:
window.addstr('*', color_pair(1))
except curses.error:
pass
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.