我有以下代码,可让您上下滚动一段文本。每次滚动(即处理用户输入)时,pad 都会按预期更新。但是,在按下第一个键之前没有显示任何内容,尽管我正在调用 pad.refresh() 就像我在每次用户输入后所做的那样。
我的代码如下所示:
def main(self,stdscr):
x,y = 20,150 # size of the window
u,a = 10,20 # where to place window - up,across
pad = curses.newpad(20,150) # nlines, ncols
pad_pos = 0
exit = False
pad.addstr(0,0,str(self.all_results))
while not exit:
pad.addstr(0,0,str(self.format_results()))
++ stdscr.refresh()
pad.refresh(pad_pos,10, u,a, x,y)
-- cmd = stdscr.getch()
++ cmd = pad.getch()
stdscr.nodelay(1)
+ pad.getch() - caused the screen not to update
+ stdscr.refresh() - no change
if cmd != -1:
+ pad.getch() - - caused the screen not to update
if cmd == curses.KEY_DOWN:
if pad_pos < 3:
pad_pos += 1
try:
pad.refresh(pad_pos,0, u,a, x,y)
except curses.error:
pass
elif cmd == curses.KEY_UP:
if pad_pos != 0:
pad_pos -= 1
try:
pad.refresh(pad_pos,0, u,a, x,y)
except curses.error:
pass
编辑:代码中显示的更改已尝试的内容(+、++、--)