的前两个参数addstr
应该是行,列作为整数,但你正在传递列表:
要使正方形像这样:
for x in range(23,42): # horizontal c
for y in range(5,24): # verticale r
stdscr.addstr(y, x, '#')
要填充颜色、闪烁、粗体等,您可以在函数中使用属性字段:
from curses import *
def main(stdscr):
start_color()
stdscr.clear() # clear above line.
stdscr.addstr(0, 0, "Fig: SQUARE", A_UNDERLINE|A_BOLD)
init_pair(1, COLOR_RED, COLOR_WHITE)
init_pair(2, COLOR_BLUE, COLOR_WHITE)
pair = 1
for x in range(3, 3 + 5): # horizontal c
for y in range(4, 4 + 5): # verticale r
pair = 1 if pair == 2 else 2
stdscr.addstr(y, x, '#', color_pair(pair))
stdscr.addstr(11, 0, 'Press Key to exit: ')
stdscr.refresh()
stdscr.getkey()
wrapper(main)
输出:
旧答案:
对角线这样做:
for c, r in zip(range(23,42), range(5,24)) :
stdscr.addstr(c, r, '#')
填充对角线的代码示例:
code x.py
from curses import wrapper
def main(stdscr):
stdscr.clear() # clear above line.
for r, c in zip(range(5,10),range(10, 20)) :
stdscr.addstr(r, c, '#')
stdscr.addstr(11, 0, 'Press Key to exit: ')
stdscr.refresh()
stdscr.getkey()
wrapper(main)
run: python x.py
,然后你可以看到:
要制作一个正方形,请执行以下操作:
from curses import wrapper
def main(stdscr):
stdscr.clear() # clear above line.
for r in range(5,10):
for c in range(10, 20):
stdscr.addstr(r, c, '#')
stdscr.addstr(11, 0, 'Press Key to exit: ')
stdscr.refresh()
stdscr.getkey()
wrapper(main)
输出:
PS:从你的代码看来你想填充对角线,所以我稍后编辑了正方形的答案。