【发布时间】:2018-06-23 21:29:13
【问题描述】:
我一直试图让这个脚本按预期工作,但在这样做时遇到了一些问题。我正在尝试根据变量 pageCount 更改屏幕上显示的字符串,但到目前为止遇到了 2 个问题。
我希望在 getkey() 等待的击键之前打印第一个字符串 (page1),但我似乎无法实现这一点。当屏幕上打印新字符串时,我也无法正确刷新/清除屏幕。
解决这些问题的最佳方法是什么?
from curses import wrapper
def main(stdscr):
# Clear screen
pageCount=0
#stdscr.addstr(str(pageCount))
stdscr.clear()
while True:
key=stdscr.getkey()
if key == "KEY_LEFT":
pageCount=pageCount-1
if key == "KEY_RIGHT":
pageCount=pageCount+1
if pageCount < 1:
pageCount=10
if pageCount > 10:
pageCount=1
if pageCount==1:
stdscr.addstr("page 1")
if pageCount==2:
stdscr.addstr("page 2")
if pageCount==3:
stdscr.addstr("page 3")
if pageCount==4:
stdscr.addstr("page 4")
if pageCount==5:
stdscr.addstr("page 5")
if pageCount==6:
stdscr.addstr("page 6")
if pageCount==7:
stdscr.addstr("page 7")
if pageCount==8:
stdscr.addstr("page 8")
if pageCount==9:
stdscr.addstr("page 9")
if pageCount==10:
stdscr.addstr("page 10")
stdscr.refresh()
wrapper(main)
【问题讨论】:
标签: python curses python-curses