我对ncurses (linux)有编码问题。我试图在Python 例7中复制C中的ncurses编程方法,我确实成功地运行了这个示例。
import curses
@curses.wrapper
def main(main_screen):
w, h = 5, 3
x, y = curses.COLS // 2, curses.LINES // 2
def mkwin(w, h, x, y):
win = curses.newwin(h, w, y, x)
win.box(0, 0)
win.refresh()
return win
def clearwin(win):
win.border(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ')
win.refresh()
main_screen.addstr("Press Q to quit.")
main_screen.refresh()
testwin = mkwin(w, h, x, y)
while True:
key = main_screen.getch()
if key in {curses.KEY_BACKSPACE, ord('q')}:
break
if key == curses.KEY_LEFT:
clearwin(testwin)
del testwin
x -= 1
testwin = mkwin(w, h, x, y)
if key == curses.KEY_RIGHT:
clearwin(testwin)
del testwin
x += 1
testwin = mkwin(w, h, x, y)
if key == curses.KEY_UP:
clearwin(testwin)
del testwin
y -= 1
testwin = mkwin(w, h, x, y)
if key == curses.KEY_DOWN:
clearwin(testwin)
del testwin
y += 1
testwin = mkwin(w, h, x, y)但是,我想删除包含该"Press Q to quit."消息的第一个屏幕。所以我改变了
main_screen.addstr("Press Q to quit.")
main_screen.refresh()
testwin = mkwin(w, h, x, y)至
testwin = mkwin(w, h, x, y)但相反,我有一个空的第一个屏幕,将停留直到我按下一个键。显然,getch()函数的main_screen导致整个屏幕清除,所以我必须使用getch()的testwin。
但是,testwin.getch()方法不返回单个键按下的很好的整数代码:相反,它返回微调键代码。例如,它返回27,然后返回91,而不是单个259 main_screen.getch()返回。如何配置testwin以使getch返回testwin和main_screen的值?
注意:我尝试使用main_screen.subwin而不是curses.newwin,但是它没有改变任何东西。
https://stackoverflow.com/questions/73145558
复制相似问题