Stopping a loop with user input. in curses

Raymond Arthur St. Marie II of III rastm2 at aol.commorespam
Sun Jul 20 19:22:18 CEST 2003

Hey Alex, 

You know, it didn't occure to me till hours later that all you really had to do
is move the second while loop into the "theClock()" definition like this. Same
reason applies.

# Import curses module

import curses, time
stdscr = curses.initscr()

def theClock():
    # Define global colour scheme
    curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE)
    # Get the screen size
    max_y, max_x = stdscr.getmaxyx()
    # Calculate the clock position relative to the screen size
    clock_x = max_x - 28 
    # Draw the clock
    clockWindow = curses.newwin(3, 26, 1, clock_x)
    clockWindow.bkgd(' ', curses.color_pair(1))

    # If 'q' is pressed, exit
    finished = 0
    while not finished:
    c = stdscr.getch()
    if c == ord('q'):
        finished = 1
    t = time.asctime()
    clockWindow.addstr(1, 1, t)

def main(stdscr):

    # Bring up the clock function


if __name__ == '__main__':

More information about the Python-list mailing list