Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #18274 > unrolled thread

Re: python curses wrapper

Started byAlexander Kapps <alex.kapps@web.de>
First post2011-12-31 20:49 +0100
Last post2011-12-31 20:49 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: python curses wrapper Alexander Kapps <alex.kapps@web.de> - 2011-12-31 20:49 +0100

#18274 — Re: python curses wrapper

FromAlexander Kapps <alex.kapps@web.de>
Date2011-12-31 20:49 +0100
SubjectRe: python curses wrapper
Message-ID<mailman.4279.1325360980.27778.python-list@python.org>
On 31.12.2011 20:34, Alexander Kapps wrote:
> On 31.12.2011 20:24, Mag Gam wrote:
>> Hello,
>>
>> I have been struggling reseting the terminal when I try to do
>> KeyboardInterrupt exception therefore I read the documentation for
>> curses.wrapper and it seems to take care of it for me,
>> http://docs.python.org/library/curses.html#curses.wrapper.
>>
>> Can someone please provide a Hello World example with python
>> curses wrapper?
>>
>> tia
>
> Use atexit.register() to register a cleanup function which is called
> when the program exits:

Oh, sorry, I missed the curses.wrapper() part. Here is an example:


import curses

def main(screen):
     curses.start_color()
     curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLUE)
     curses.init_pair(2, curses.COLOR_YELLOW, curses.COLOR_BLACK)

     screen.bkgd(curses.color_pair(1))
     screen.refresh()

     win = curses.newwin(5, 20, 5, 5)
     win.bkgd(curses.color_pair(2))
     win.box()
     win.addstr(2, 2, "Hallo, Welt!")
     win.refresh()

     c = screen.getch()

try:
     curses.wrapper(main)
except KeyboardInterrupt:
     print "Got KeyboardInterrupt exception. Exiting..."
     exit()

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web