[英]Python Curses addwstr() returned ERR when adding lines to screen
Suppose I am adding a large number of lines to a curses screen.假设我将大量行添加到curses 屏幕。
Minimal non-working example:最小的非工作示例:
import curses
class MyApp(object):
def __init__(self, stdscreen):
self.screen = stdscreen
for i in range(0,100):
self.screen.addstr(str(i) + '\n')
self.screen.refresh()
self.screen.getch()
if __name__ == '__main__':
curses.wrapper(MyApp)
The above code returns:上面的代码返回:
Traceback (most recent call last):
File "test.py", line 17, in <module>
curses.wrapper(MyApp)
File "/usr/lib/python3.7/curses/__init__.py", line 94, in wrapper
return func(stdscr, *args, **kwds)
File "test.py", line 11, in __init__
self.screen.addstr(str(i) + '\n')
_curses.error: addwstr() returned ERR
Press ENTER to continue
1) What is this error? 1)这是什么错误? 2) If the error is because I am adding too many lines to the screen, how could I list those entries with curses?
2)如果错误是因为我在屏幕上添加了太多行,我怎么能用curses列出这些条目? Perhaps with a scroll view of some sort?
也许带有某种滚动视图?
It occurred to me that I could use try
/ except
to determine the maximum number of lines that can be printed on the screen to avoid this error:我突然想到我可以使用
try
/ except
来确定可以在屏幕上打印的最大行数以避免此错误:
import curses
class MyApp(object):
def __init__(self, stdscreen):
self.screen = stdscreen
maximum = self.maxlines()
for i in range(maximum):
self.screen.addstr(str(i) + '\n')
self.screen.refresh()
self.screen.getch()
def maxlines(self):
n = 0
try:
for i in range(100):
self.screen.addstr(str(i) + '\n')
n += 1
except:
pass
self.screen.erase()
return n
if __name__ == '__main__':
curses.wrapper(MyApp)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.