there. Can anyone tell me what I did wrong in the code? Why the timer function doesn't appear in the box?
import curses
from datetime import datetime
stdsrc= curses.initscr()
SPACE_KEY = ord(' ')
box1 = curses.newwin(20, 30, 10, 10)
box1.box()
def run(win):
win.timeout(1000)
start = datetime.now()
while True:
now = datetime.now()
minutes, seconds = divmod((now - start).total_seconds(), 60)
win.addstr(0, 0, "%02d:%02d" % (minutes, round(seconds)))
c = win.getch() # c variable to get user character
if c == SPACE_KEY:
break
box1.refresh()
curses.wrapper(run)
curses.endwin()
The first two arguments to addstr
are the coordinates to start the text. In you code you are starting the text at the coordinates 0,0
, whereas your box starts at coordinates 20,30
.