I've tried win.inch(y,x)
and win.instr(y,x)
, even win.getch()
and win.getkey()
. None can achieve the detective effect? I've searched through stackoverflow and google, but so far I didn't find the solution. I've already read the curses manual of python. But still can't solve this.
My code:
import curses
stdscr = curses.initscr()
stdscr.addstr(1,1,'x')
if stdscr.inch(1,1) == 'x':
stdscr.addstr(2,1,'success')
stdscr.refresh()
stdscr.getch()
curses.endwin()
I've run this piece of code, but no "successs" was show on the screen. I've debug my code for 4 hours last night. And I'm sure I was stuck at this value judge claim " if stdscr.inch(1,1,) == 'x'
: ". How could I realize my purpose to see if there is a specific string at a coordinate and then do the correspond action?
curses.window.inch
returns an int
, not a str
.
The following line:
if stdscr.inch(1, 1) == 'x':
should be:
if stdscr.inch(1, 1) & 0xff == ord('x'):
or using instr
(without specifying length, instr
returns a string that start at the given position to the end of the line):
if stdscr.instr(1, 1, 1) == 'x':