Stopping a loop with user input. in curses
Alex
bogus at antispam.com
Sat Jul 19 17:26:34 EDT 2003
Hello all,
I've written a small clock program in curses that I would
like to have end when someone presses 'q'. I've included the
code below. I'm *very* new to python so I apologize in advance if
this seems like a horribly obvious problem. I've spent all day
trying various structures but none of them have worked out.
Any help would be greatly appreciated.
Thanks,
Alex
#! /usr/bin/python
# 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))
clockWindow.box()
clockWindow.refresh()
while 1:
t = time.asctime()
clockWindow.addstr(1, 1, t)
clockWindow.refresh()
time.sleep(1)
def main(stdscr):
# Bring up the clock function
theClock()
# If 'q' is pressed, exit
while 2:
c = stdscr.getch()
if c == ord('q'):
curses.beep()
break
if __name__ == '__main__':
curses.wrapper(main)
More information about the Python-list
mailing list