Python Curses中的addstr延迟

时间:2015-06-10 11:15:56

标签: python python-2.7 ncurses curses python-curses

我正在使用AI并且我正在使用Curses,我希望能够添加消息,等待五秒钟然后再绘制另一条消息。

以下是我要修复的内容

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import curses
import time

screen = curses.initscr()
curses.noecho()
curses.curs_set(0)
screen.keypad(1)

screen.addstr("This is a Sample Curses Script\n\n")
screen.addstr("This is a Sample Curses Script\n\n")
time.sleep(5)
screen.addstr("This is a Sample Curses Script\n\n")
while True:
   event = screen.getch()
   if event == ord("q"): break

curses.endwin()

1 个答案:

答案 0 :(得分:1)

来自official guide

  

当您在窗口上放置所需的窗口后,当您希望窗口所覆盖的终端部分看起来像它时,您必须调用refresh()。

因此,请更改您的代码:

import curses
import time

screen = curses.initscr()
curses.noecho()
curses.curs_set(0)
screen.keypad(1)

screen.addstr("This is a Sample Curses Script\n\n")
screen.addstr("This is a Sample Curses Script\n\n")
screen.refresh()
time.sleep(5)
screen.addstr("This is a Sample Curses Script\n\n")
screen.refresh()
while True:
    event = screen.getch()
    if event == ord("q"): break

curses.endwin()