简体   繁体   English

Python诅咒中的addstr延迟

[英]addstr delay in Python Curses

I'm working on an AI and I am using Curses and I would like to be able to add a message, wait five seconds then draw another message. 我正在使用AI,并且正在使用Curses,所以我希望能够添加一条消息,等待五秒钟,然后绘制另一条消息。

Below is the piece I am trying to fix 以下是我要修复的部分

#!/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()

From the official guide : 官方指南

After you have put on the window what you want there, when you want the portion of the terminal covered by the window to be made to look like it, you must call refresh(). 在窗口上放置了所需的内容之后,当要使窗口覆盖的终端部分看起来像它时,必须调用refresh()。

Thus, change your code as such: 因此,可以这样更改代码:

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM