Python and time / datetime
<p>I've recently began work on a Python program as seen in the fragment below.</p>

<pre><code># General Variables
running = False
new = True
timeStart = 0.0
timeElapsed = 0.0

def endProg():
    curses.nocbreak()
    stdscr.keypad(False)
    curses.echo()
    curses.endwin()
    quit()

# Draw
def draw():
    stdscr.addstr(1, 1, "&gt;", curses.color_pair(6))
    stdscr.border()
    if running:
        stdscr.addstr(1, 3, t.strftime( "%H:%M.%S", t.ctime( timeStart - timeElapsed ) ) )

        stdscr.redrawwin()
    stdscr.refresh()

# Calculate
def calc():
    if running:
        timeElapsed = t.clock() - timeStart

stdscr.border()
stdscr.addstr(1, 3, t.strftime( "%H:%M.%S", t.gmtime( t.clock() - t.clock() ) ) )

# Main Loop
while True:
    # Get Input
    kInput = stdscr.getch()

    # Close the program
    if kInput == ord('q'):
        endProg()

    # Stop the current run
    elif kInput == ord('s'):
        stdscr.addstr(1, 3, t.strftime( "%H:%M.%S", t.gmtime( t.clock() - t.clock() ) ) )
        running = False
        new = True

    # Start a run
    elif kInput == ord(' ') and new:
        running = not running
        new = not new
        timeStart = dt.datetime.now()

    # Toggle the timer
    elif kInput == ord('p') and not new:
        timeStart = dt.datetime.now() - timeStart
        running = not running

    calc()
    draw()
</code></pre>

<p><strong>My program is a bit between solutions currently</strong>, sorry if something doesn't look right. I'll be more than happy to explain.</p>

<p>I've spent the last several hours reading online about the time and datetime modules for python, trying to figure out how I can use them to accomplish my goals, but however I've tried to implement them it's been no use.</p>

<p>Essentially, I need my program to measure the elapsed time from when a button is pressed and be able to display it in a hour:minute.second format. The subtraction has made it very difficult, having to implement things such as timedelta. From what I have read online there is no way to do what I'm wanting without the datetime module, but it's given me nothing but problems.</p>

<p>Is there an easier solution, does my code have any outstanding errors, and how stupid am I?</p>

<pre><code>def draw():
    stdscr.border()
    if running:
        stdscr.addstr(1, 1, "&gt;", curses.color_pair(8))
        stdscr.addstr(1, 3, t.strftime( "%H:%M.%S", t.gmtime( timeElapsed ) ) )

    if not running:
        stdscr.addstr(1, 1, "&gt;", curses.color_pair(7))

    stdscr.redrawwin()
    stdscr.refresh()

# Calculate
def calc():
    if running:
        timeElapsed = t.time() - timeStart

stdscr.border()
stdscr.addstr(1, 3, t.strftime( "%H:%M.%S", t.gmtime( t.time() - t.time() ) ) )

# Main Loop
while True:
    # Get Input
    kInput = stdscr.getch()

    # Close the program
    if kInput == ord('q'):
        endProg()

    # Stop the current run
    elif kInput == ord('s'):
        running = False
        new = True

    # Start a run
    elif kInput == ord(' ') and new:
        running = not running
        new = not new
        timeStart = t.time()

    # Toggle the timer
    elif kInput == ord('p') and not new:
        running = not running
        timeStart = t.time() - timeStart

    calc()
    draw()
</code></pre>

<p>Well, I managed to get rid of all of the errors I was encountering. However, the time displayed is incorrect.</p>

<p>Since we're looking to find the elapsed time, it should start at 0 and increase. My program is starting at 12:21.xx and increasing.</p>

<p>Looking at my code I don't see any errors, but there's obviously one in there somewhere.</p>

python datetime time timer