[Tutor] curses.wrapper() question

Michael Janssen Janssen@rz.uni-frankfurt.de
Thu Jul 17 18:45:02 2003


On Fri, 18 Jul 2003, Michael Janssen wrote:

> Hi Alex,
>
> curses.wrapper() is very easy to use :-) But you have to redesign your
> script for this....
>
> curses.wrapper takes a function as argument. But what for a function? The
> "main" function for your curses application that does *all* the logic.
>
> By now you write your script much like a shell-script doing one step after
> another. This is a typical way to start, not that efficient (in terms of
> maintainable code) and unfortunatelly a no-go-way for curses.wrapper.
>
> A better design would be:
>
> 1. setting some global constants (if at all)
>
> 2. definining a "main" function (you can call it at wil, but "main" is
> often used) that does all the logic (mostly by calling subfunctions)

I have forgotten one important thing: curses.wrapper will send the curses
main window ("stdscr") to main as an argument.

So you must write your main-function in that way, that it will *take* this
argument.

def main(stdscr):
    stdscr.addstr(0, 0, "Hello World!") # or what you want

is nice.

Michael