Goto XY

A

ale.of.ginger

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.
 
D

David Wahler

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
 
M

Mike Meyer

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
 
A

ale.of.ginger

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...)
 
D

David Wahler

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
 
J

jmdeschamps

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()
 
C

Chris F.A. Johnson

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.
 
C

Chris F.A. Johnson

[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.
 
C

Chris F.A. Johnson

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.
 
A

ale.of.ginger

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.
 
R

Richie Hindle

[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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top