Search code examples
python-3.6sleepcursespython-curses

unicurses' addstr() interferes with time.sleep()


The time.sleep() delay will sleep before addstr() in the script below

from unicurses import *
from time import *
stdscr = initscr()
addstr("Hello")
sleep(1)
endwin()

Is there any curses function for delays?


Solution

  • Use napms rather than sleep. It works with other python/curses bindings.

    The example

    from unicurses import *
    from time import *
    stdscr = initscr()
    addstr("Hello")
    sleep(1)
    endwin()
    

    looks odd, since there is no explicit refresh call in endwin. Something like this might work for you:

    from unicurses import *
    from time import *
    stdscr = initscr()
    addstr("Hello")
    refresh()
    napms(1000)
    endwin()