[英]Why can't I addstr() to last row/col in python curses window?
使用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))
這將阻止滾動,從而允許您打印最后一行中的最后一個字符
您需要像寬度一樣從寬度減去1。 否則字符串將超過屏幕的寬度。
screen.addstr(ScreenH - 1, ScreenW - 1 - cloclen, cloc, curses.color_pair(1))
^^^
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.