使用Python,我尝试使用addstr() 将光标位置写入curses 窗口的右下角,但出现错误。ScreenH-2
工作正常,但打印在窗口底部的第二行。ScreenH-1
根本不起作用。我究竟做错了什么?
import curses
ScreenH = 0
ScreenW = 0
CursorX = 1
CursorY = 1
def repaint(screen):
global ScreenH
global ScreenW
global CursorX
global CursorY
ScreenH, ScreenW = screen.getmaxyx()
cloc = ' ' + str(CursorX) + ':' + str(CursorY) + ' '
cloclen = len (cloc)
screen.addstr (ScreenH - 1, ScreenW - cloclen, cloc, curses.color_pair(1));
def Main(screen):
curses.init_pair (1, curses.COLOR_WHITE, curses.COLOR_BLUE)
repaint (screen)
while True:
ch = screen.getch()
if ch == ord('q'):
break
repaint (screen)
curses.wrapper(Main)
File "test.py", line 17, in repaint
screen.addstr (ScreenH - 1, ScreenW - cloclen, cloc, curses.color_pair(1));
_curses.error: addstr() returned ERR
你也可以使用insstr
代替addstr
:
screen.insstr(ScreenH - 1, ScreenW - 1 - cloclen, cloc, curses.color_pair(1))
这将阻止滚动,从而允许您打印到最后一行的最后一个字符
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)