添加到新 window 的文本在 Curses 中不可见
Text added to New window is not visible in Curses
我正在尝试添加一个 window 和这个 window 中的一个文本,使用 this 和这个:
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
的文本可见,但 "Example String" 不可见。
我如何操作 windows 使该文本可见?
初始化时,标准屏幕有待更新(清除屏幕)。 add_window_and_str
末尾的 refresh
调用会执行此操作,覆盖 win.addstr
输出。您可以将该调用 移动到 第一次调用 add_window_and_str
之前。之后,对 stdscr
的更改将出现在 window.
之外的部分屏幕中
还有一个问题:调用 getch
会刷新关联的 window。通常程序的组织方式是 getch
与您希望保留 "on top" 的任何 window 相关联,这样它们的更新就不会被其他 windows 遮挡。如果您 return 来自 add_window_and_str
的 win
变量,您可以将 window 与 getch
.
一起使用
我正在尝试添加一个 window 和这个 window 中的一个文本,使用 this 和这个:
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
的文本可见,但 "Example String" 不可见。
我如何操作 windows 使该文本可见?
初始化时,标准屏幕有待更新(清除屏幕)。 add_window_and_str
末尾的 refresh
调用会执行此操作,覆盖 win.addstr
输出。您可以将该调用 移动到 第一次调用 add_window_and_str
之前。之后,对 stdscr
的更改将出现在 window.
还有一个问题:调用 getch
会刷新关联的 window。通常程序的组织方式是 getch
与您希望保留 "on top" 的任何 window 相关联,这样它们的更新就不会被其他 windows 遮挡。如果您 return 来自 add_window_and_str
的 win
变量,您可以将 window 与 getch
.