curses and python (linux, debian)

Discussion in 'Python' started by Guido, May 3, 2004.

  1. Guido

    Guido Guest

    Hello

    I'm new to python and i'm trying to write a script
    that shows a menu.

    Now, I have some troubles with curses.setsyx()

    I do:

    import curses

    curses.setsyx(2, 20)
    curses.putp("TEST TITLE")
    curses.setsyx(25, 35)
    curses.putp("TEST CENTER")
    curses.setsyx(12, 35)
    curses.putp("TEST CENTER")

    but it just prints all the string after each other
    at the first lines..

    can anybody help me please?

    thx!
    Guido, May 3, 2004
    #1
    1. Advertising

  2. At some point, Guido <> wrote:

    > Hello
    >
    > I'm new to python and i'm trying to write a script that shows a menu.
    >
    > Now, I have some troubles with curses.setsyx()
    >
    > I do:
    >
    > import curses
    >
    > curses.setsyx(2, 20)
    > curses.putp("TEST TITLE")
    > curses.setsyx(25, 35)
    > curses.putp("TEST CENTER")
    > curses.setsyx(12, 35)
    > curses.putp("TEST CENTER")
    >
    > but it just prints all the string after each other at the first
    > lines..


    Er, that's really the wrong way to do it. For one thing, curses.putp
    doesn't do what you think you want it to do. Have a look at "Curses
    Programming with Python":
    http://www.amk.ca/python/howto/curses/

    Something like this:

    import curses

    def main(stdscr):
    stdscr.addstr(2, 20, "TEST TITLE")
    stdscr.addstr(25,35, "TEST CENTER")
    stdscr.addstr(12,35, "TEST CENTER")
    while 1:
    c = stdscr.getch()
    if c == ord('q'):
    return

    curses.wrapper(main)

    --
    |>|\/|<
    /--------------------------------------------------------------------------\
    |David M. Cooke
    |cookedm(at)physics(dot)mcmaster(dot)ca
    David M. Cooke, May 3, 2004
    #2
    1. Advertising

  3. Guido <> writes:

    > Hello
    >
    > I'm new to python and i'm trying to write a script that shows a menu.
    >
    > Now, I have some troubles with curses.setsyx()
    >
    > I do:
    >
    > import curses
    >
    > curses.setsyx(2, 20)
    > curses.putp("TEST TITLE")
    > curses.setsyx(25, 35)
    > curses.putp("TEST CENTER")
    > curses.setsyx(12, 35)
    > curses.putp("TEST CENTER")
    >
    > but it just prints all the string after each other at the first
    > lines..
    >
    > can anybody help me please?


    Don't you call initscr() first?

    Cheers,
    mwh

    --
    ZAPHOD: OK, so ten out of ten for style, but minus several million
    for good thinking, eh?
    -- The Hitch-Hikers Guide to the Galaxy, Episode 2
    Michael Hudson, May 4, 2004
    #3
  4. Guido

    Guido Guest

    David M. Cooke wrote:

    > At some point, Guido <> wrote:
    >
    >
    >>Hello
    >>
    >>I'm new to python and i'm trying to write a script that shows a menu.
    >>
    >>Now, I have some troubles with curses.setsyx()
    >>
    >>I do:
    >>
    >>import curses
    >>
    >>curses.setsyx(2, 20)
    >>curses.putp("TEST TITLE")
    >>curses.setsyx(25, 35)
    >>curses.putp("TEST CENTER")
    >>curses.setsyx(12, 35)
    >>curses.putp("TEST CENTER")
    >>
    >>but it just prints all the string after each other at the first
    >>lines..

    >
    >
    > Er, that's really the wrong way to do it. For one thing, curses.putp
    > doesn't do what you think you want it to do. Have a look at "Curses
    > Programming with Python":
    > http://www.amk.ca/python/howto/curses/
    >
    > Something like this:
    >
    > import curses
    >
    > def main(stdscr):
    > stdscr.addstr(2, 20, "TEST TITLE")
    > stdscr.addstr(25,35, "TEST CENTER")
    > stdscr.addstr(12,35, "TEST CENTER")
    > while 1:
    > c = stdscr.getch()
    > if c == ord('q'):
    > return
    >
    > curses.wrapper(main)
    >


    thx very much

    very handy tutorial!

    Now, i'm using DrPython, it looks fine, but i
    can't debug my curses program

    It gives an error with this message:
    curses.wrapper returned ERR on curses.cbreak

    if i run it with python, it works!

    anybody?
    Guido, May 4, 2004
    #4
  5. Guido

    Guido Guest

    Michael Hudson wrote:

    > Guido <> writes:
    >
    >
    >>Hello
    >>
    >>I'm new to python and i'm trying to write a script that shows a menu.
    >>
    >>Now, I have some troubles with curses.setsyx()
    >>
    >>I do:
    >>
    >>import curses
    >>
    >>curses.setsyx(2, 20)
    >>curses.putp("TEST TITLE")
    >>curses.setsyx(25, 35)
    >>curses.putp("TEST CENTER")
    >>curses.setsyx(12, 35)
    >>curses.putp("TEST CENTER")
    >>
    >>but it just prints all the string after each other at the first
    >>lines..
    >>
    >>can anybody help me please?

    >
    >
    > Don't you call initscr() first?
    >
    > Cheers,
    > mwh
    >


    i did, but i forget to copy it
    Guido, May 4, 2004
    #5
  6. At some point, Guido <> wrote:

    > David M. Cooke wrote:
    >
    >> At some point, Guido <> wrote:
    >>
    >>>Hello
    >>>
    >>>I'm new to python and i'm trying to write a script that shows a menu.
    >>>
    >>>Now, I have some troubles with curses.setsyx()
    >>>
    >>>I do:
    >>>
    >>>import curses
    >>>
    >>>curses.setsyx(2, 20)
    >>>curses.putp("TEST TITLE")
    >>>curses.setsyx(25, 35)
    >>>curses.putp("TEST CENTER")
    >>>curses.setsyx(12, 35)
    >>>curses.putp("TEST CENTER")
    >>>
    >>>but it just prints all the string after each other at the first
    >>>lines..

    >> Er, that's really the wrong way to do it. For one thing, curses.putp
    >> doesn't do what you think you want it to do. Have a look at "Curses
    >> Programming with Python":
    >> http://www.amk.ca/python/howto/curses/
    >> Something like this:
    >> import curses
    >> def main(stdscr):
    >> stdscr.addstr(2, 20, "TEST TITLE")
    >> stdscr.addstr(25,35, "TEST CENTER")
    >> stdscr.addstr(12,35, "TEST CENTER")
    >> while 1:
    >> c = stdscr.getch()
    >> if c == ord('q'):
    >> return
    >> curses.wrapper(main)
    >>

    >
    > thx very much
    >
    > very handy tutorial!
    >
    > Now, i'm using DrPython, it looks fine, but i can't debug my curses
    > program
    >
    > It gives an error with this message: curses.wrapper returned ERR on
    > curses.cbreak


    I'm not familiar with DrPython, but it looks like a IDE. The console
    widget it uses for the Python shell probably doesn't support enough to
    be a 'real' terminal, so curses likely doesn't work in it. You'll have
    to run it in a terminal program like xterm.

    > if i run it with python, it works!


    From the command line, right? There you go :)

    --
    |>|\/|<
    /--------------------------------------------------------------------------\
    |David M. Cooke
    |cookedm(at)physics(dot)mcmaster(dot)ca
    David M. Cooke, May 4, 2004
    #6
  7. Guido

    Guido Guest

    David M. Cooke wrote:

    >>
    >>Now, i'm using DrPython, it looks fine, but i can't debug my curses
    >>program
    >>
    >>It gives an error with this message: curses.wrapper returned ERR on
    >>curses.cbreak

    >
    >
    > I'm not familiar with DrPython, but it looks like a IDE. The console
    > widget it uses for the Python shell probably doesn't support enough to
    > be a 'real' terminal, so curses likely doesn't work in it. You'll have
    > to run it in a terminal program like xterm.
    >
    >
    >>if i run it with python, it works!

    >
    >
    > From the command line, right? There you go :)
    >


    well, I like a good editor, and DrPython seemed nice.

    Do you have any other suggestions?

    Otherwise I'll stay with the combo solution
    Guido, May 5, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Konrad Koller
    Replies:
    3
    Views:
    768
    Konrad Koller
    Jan 9, 2005
  2. Jean-Paul Calderone
    Replies:
    2
    Views:
    436
    Joel Hedlund
    Feb 9, 2006
  3. Luke Kenneth Casson Leighton
    Replies:
    0
    Views:
    467
    Luke Kenneth Casson Leighton
    Dec 31, 2008
  4. patrickwayodi
    Replies:
    6
    Views:
    910
    Anssi Saari
    Dec 14, 2011
  5. Gary Roach
    Replies:
    2
    Views:
    112
    D.M. Procida
    Nov 13, 2013
Loading...

Share This Page