小编M. *_*del的帖子

Python3 + Curses:如何立即按"q"结束程序?

当我运行以下示例代码并按下"q"时,它将正确结束,但如果我按下任何其他字符"例如许多休息和许多其他字符"然后按"q"它将不会退出,我该怎么解决这个问题?

import curses, time

def main(sc):
    sc.nodelay(1)

    while True:
        sc.addstr(1, 1, time.strftime("%H:%M:%S"))
        sc.refresh()

        if sc.getch() == ord('q'):
            break

        time.sleep(1)

if __name__=='__main__': curses.wrapper(main)
Run Code Online (Sandbox Code Playgroud)

python curses ncurses python-3.x python-curses

4
推荐指数
1
解决办法
1596
查看次数

标签 统计

curses ×1

ncurses ×1

python ×1

python-3.x ×1

python-curses ×1