0

我正在研究 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()
4

1 回答 1

1

来自官方指南

在窗口上放上你想要的东西之后,当你想让窗口覆盖的终端部分看起来像它时,你必须调用 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()
于 2015-06-10T12:34:58.687 回答