Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Getch在调用之前获取输入_Python_Python Curses - Fatal编程技术网

Python Getch在调用之前获取输入

Python Getch在调用之前获取输入,python,python-curses,Python,Python Curses,我正在用python编写一个curses应用程序 def main(stdscr): stuff(stdscr) def printStuff(stdscr, string): stdscr.clear() stdscr.addstr(0, 0, string) stdscr.refresh() def stuff(stdscr): printStuff(stdscr, 'foo') time.sleep(3) printStuff(s

我正在用python编写一个curses应用程序

def main(stdscr):
    stuff(stdscr)

def printStuff(stdscr, string):
    stdscr.clear()
    stdscr.addstr(0, 0, string)
    stdscr.refresh()

def stuff(stdscr):
    printStuff(stdscr, 'foo')
    time.sleep(3)
    printStuff(stdscr, 'bar')
    stdscr.getch()

wrapper(main)
当我运行代码时,大部分情况下一切都很好。
如果我在睡眠时在三秒钟的间隔内按下一个按钮,getch将很乐意将其作为输入,即使在调用getch之前按下了该按钮。这是为什么?我如何解决这个问题?

输入是缓冲的,
getch()
处理输入缓冲区中的任何内容。您可以使用清除缓冲区


输入被缓冲,并且
getch()
处理输入缓冲区中的任何内容。您可以使用清除缓冲区


您所做的一切都被放入一个输入队列
getch
处理队列中的任何内容。您所做的一切都被放入一个输入队列
getch
处理队列中的任何内容。
def stuff(stdscr):
    printStuff(stdscr, 'foo')
    time.sleep(3)
    printStuff(stdscr, 'bar')
    stdscr.flushinp()
    stdscr.getch()