Goto XY

Discussion in 'Python' started by ale.of.ginger@gmail.com, Nov 9, 2005.

  1. Guest

    Is there some command in python so that I can read a key's input and
    then use a gotoxy() function to move the cursor on screen? e.g.:
    (psuedo-code)

    When the right arrow is pushed, cursor gotoxy(x+1,y)

    Thanks.
     
    , Nov 9, 2005
    #1
    1. Advertising

  2. David Wahler Guest

    wrote:
    > Is there some command in python so that I can read a key's input and
    > then use a gotoxy() function to move the cursor on screen? e.g.:
    > (psuedo-code)
    >
    > When the right arrow is pushed, cursor gotoxy(x+1,y)
    >
    > Thanks.


    On Unix-like platforms, this functionality is provided by the standard
    curses module. A similar module for Windows appears to be available at
    http://www.effbot.org/zone/console-index.htm but I haven't tested it
    out.

    -- David
     
    David Wahler, Nov 9, 2005
    #2
    1. Advertising

  3. Mike Meyer Guest

    writes:

    > Is there some command in python so that I can read a key's input and
    > then use a gotoxy() function to move the cursor on screen? e.g.:
    > (psuedo-code)
    >
    > When the right arrow is pushed, cursor gotoxy(x+1,y)


    You want curses. A version is included in the standard library if
    you're on Unix. If you're on Windows, there are third party curses
    libraries. You should be able to install that and then build the
    curses module against it. If you're not on either of those two - tell
    us what you're using, and maybe someone who knows that system will
    answer you.

    <mike
    --
    Mike Meyer <> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
     
    Mike Meyer, Nov 9, 2005
    #3
  4. Guest

    , Nov 9, 2005
    #4
  5. Guest

    Thanks -- I downloaded WConio.

    When I just tried it out in the IDLE, it said:

    NameError: name 'WConio' is not defined

    I assume I have to use a header somewhere (import WConio ?). Or is
    there something I'm missing (I downloaded the Python 2.4 (I have 2.4.2)
    auto installer and it ran fine...)
     
    , Nov 9, 2005
    #5
  6. David Wahler Guest

    wrote:
    > I assume I have to use a header somewhere (import WConio ?).


    If you had tried it, you would have discovered that "import WConio" is
    exactly what you need. Don't be afraid to experiment!

    -- David
     
    David Wahler, Nov 9, 2005
    #6
  7. Guest

    Like David said below, you need to import WConio but then repemeber
    when you *import someLib* you have to use qualified names such as
    WConio.getkey()

    Example:
    import WConio

    s=WConio.getkey()

    if s == "right":
    WConio.gotoxy(10,10)
    WConio.putch("W")

    s=WConio.getch()
     
    , Nov 9, 2005
    #7
  8. Guest

    Like David said above... ;-)
     
    , Nov 9, 2005
    #8
  9. On 2005-11-09, wrote:
    > Is there some command in python so that I can read a key's input and
    > then use a gotoxy() function to move the cursor on screen? e.g.:
    > (psuedo-code)


    You can use curses, but that may be more trouble than it's worth.

    If you don't mind limiting your program to an ANSI-type terminals
    (vt100, xterm, rxvt, linux, putty, etc....), then you can just use
    the codes to position the cursor:

    ESC = '\033'
    CSI = ESC + "["

    def printat(row,col,arg=""):
    sys.stdout.write( CSI + str(row) + ";" + str(col) + 'H' + str(arg))

    > When the right arrow is pushed, cursor gotoxy(x+1,y)


    To read a single keystroke, see Claudio Grondi's post in the
    thread "python without OO" from last January.

    Function and cursor keys return more than a single character, so
    more work is required to decode them. The principle is outlined in
    <http://www.unixreview.com/documents/s=9920/ur0511a/ur0511a.html>;
    the code there is for the shell, but translating them to python
    should be straightforward. I'll probably do it myself when I have
    the time or the motivation.

    --
    Chris F.A. Johnson | Author:
    <http://cfaj.freeshell.org> | Shell Scripting Recipes:
    Any code in this post is released | A Problem-Solution Approach,
    under the GNU General Public Licence | 2005, Apress
     
    Chris F.A. Johnson, Nov 9, 2005
    #9
  10. On 2005-11-09, Chris F.A. Johnson <> wrote:
    >
    >> Is there some command in python so that I can read a key's input and
    >> then use a gotoxy() function to move the cursor on screen? e.g.:
    >> (psuedo-code)

    >
    > You can use curses, but that may be more trouble than it's worth.


    In which case you could always use tput -- and it will still be
    portable.

    --
    Grant Edwards grante Yow! I'm GLAD I
    at remembered to XEROX all
    visi.com my UNDERSHIRTS!!
     
    Grant Edwards, Nov 9, 2005
    #10
  11. On 2005-11-09, Jean-Paul Calderone wrote:
    > On Tue, 8 Nov 2005 22:33:47 -0500, "Chris F.A. Johnson" <> wrote:
    >> [snip]
    >>
    >> To read a single keystroke, see Claudio Grondi's post in the
    >> thread "python without OO" from last January.
    >>
    >> Function and cursor keys return more than a single character, so
    >> more work is required to decode them. The principle is outlined in
    >> <http://www.unixreview.com/documents/s=9920/ur0511a/ur0511a.html>;
    >> the code there is for the shell, but translating them to python
    >> should be straightforward. I'll probably do it myself when I have
    >> the time or the motivation.
    >>

    >
    > Like this?
    >
    > http://cvs.twistedmatrix.com/cvs/trunk/twisted/conch/insults/insults.py?view=markup&rev=14863


    More or less; probably much less.

    --
    Chris F.A. Johnson | Author:
    <http://cfaj.freeshell.org> | Shell Scripting Recipes:
    Any code in this post is released | A Problem-Solution Approach,
    under the GNU General Public Licence | 2005, Apress
     
    Chris F.A. Johnson, Nov 9, 2005
    #11
  12. On 2005-11-09, Grant Edwards wrote:
    > On 2005-11-09, Chris F.A. Johnson <> wrote:
    >>
    >>> Is there some command in python so that I can read a key's input and
    >>> then use a gotoxy() function to move the cursor on screen? e.g.:
    >>> (psuedo-code)

    >>
    >> You can use curses, but that may be more trouble than it's worth.

    >
    > In which case you could always use tput -- and it will still be
    > portable.


    Not necessarily. There are differences in tput from system to
    system, not to mention how much it slows things down to call it for
    every sequence you need.

    Then there are some old systems which don't have tput.


    --
    Chris F.A. Johnson | Author:
    <http://cfaj.freeshell.org> | Shell Scripting Recipes:
    Any code in this post is released | A Problem-Solution Approach,
    under the GNU General Public Licence | 2005, Apress
     
    Chris F.A. Johnson, Nov 9, 2005
    #12
  13. Guest

    OK - I added the import WConio line. But when I run

    import WConio
    print "going to x10,y10..."
    WConio.gotoxy(10,10)
    print "Done"

    the above, I get the following error:

    WConio.gotoxy(10,10)
    error: GetConOut Failed

    I installed the WConio to the ../site-packages/ folder in Python24, and
    when it didn't work I also moved the files in there to the /Lib/ folder
    where other things are like random, but that didn't seem to work either.
     
    , Nov 9, 2005
    #13
  14. [ale.of.ginger]
    > WConio.gotoxy(10,10)
    > error: GetConOut Failed


    Are you running at a Windows Command Prompt, or in an IDE? As I understand
    it, WConio will only work in a Windows Command Prompt.

    --
    Richie Hindle
     
    Richie Hindle, Nov 9, 2005
    #14
    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. youngsun park
    Replies:
    2
    Views:
    645
    David Pursley
    Nov 18, 2003
  2. Skybuck Flying

    VHDL Goto statement ?

    Skybuck Flying, Aug 8, 2005, in forum: VHDL
    Replies:
    9
    Views:
    6,357
    ajahn
    Aug 26, 2005
  3. Skybuck Flying

    Re: VHDL Goto statement ?

    Skybuck Flying, Aug 8, 2005, in forum: VHDL
    Replies:
    0
    Views:
    771
    Skybuck Flying
    Aug 8, 2005
  4. Flip
    Replies:
    6
    Views:
    6,752
    Jeff Dillon
    Nov 18, 2004
  5. Flip
    Replies:
    1
    Views:
    671
    Brock Allen
    Apr 14, 2005
Loading...

Share This Page