python - 添加到新窗口的文本在诅咒中不可见
问题描述
我正在尝试使用这个和这个在这个窗口中添加一个窗口和一个带有诅咒的文本:
window.addstr("This is a text in a window")
代码:
class View:
def __init__(self, ):
self.stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
self.stdscr.keypad(True)
# -----------------
self.add_window_and_str()
self.add_str()
# -----------------
self.stdscr.getkey()
curses.endwin()
def add_str(self): #just text in standart screen
self.stdscr.addstr("test")
self.stdscr.refresh()
def add_window_and_str(self):
scr_limits = self.stdscr.getmaxyx()
win = curses.newwin(scr_limits[0] - 10, scr_limits[1] - 10, 5, 5)
win.addstr("Example String")
win.refresh()
self.stdscr.refresh()
添加的文本self.add_str
可见,但“示例字符串”不可见。如何操作窗口以使该文本可见?
解决方案
在初始化时,标准屏幕有一个挂起的更新(以清除屏幕)。结束时的refresh
调用add_window_and_str
会覆盖win.addstr
输出。您可以在第一次调用之前将该调用移至add_window_and_str
. 之后,更改stdscr
将出现在窗口外的部分屏幕中。
还有一个问题:调用getch
会刷新关联的窗口。通常程序的组织方式getch
是与您希望保持“在顶部”的任何窗口相关联,这样它们的更新就不会被其他窗口遮挡。如果您win
从 中返回变量add_window_and_str
,则可以将该窗口与getch
.