Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 什么';在ncurses中的指定位置添加相同符号的短方法是什么?_Python_Ncurses - Fatal编程技术网

Python 什么';在ncurses中的指定位置添加相同符号的短方法是什么?

Python 什么';在ncurses中的指定位置添加相同符号的短方法是什么?,python,ncurses,Python,Ncurses,我想在ncurse屏幕中添加str“#”,坐标为x(5到24),y(23到42) 这是一个正方形。但我想不出一个简单的方法 我试过: stdscr.addstr(range(23,42),range(5,24),'#') 但这行不通。它需要“整数” 有人能想出一个简单的方法来做这项工作吗 谢谢。addstr的前两个参数应该是row,col作为整数,但您正在传递列表: 要使正方形像这样: for x in range(23,42): # horizontal c for y in rang

我想在
ncurse
屏幕中添加str
“#”
,坐标为
x(5到24)
y(23到42)
这是一个正方形。但我想不出一个简单的方法

我试过:

stdscr.addstr(range(23,42),range(5,24),'#')
但这行不通。它需要“整数”

有人能想出一个简单的方法来做这项工作吗


谢谢。

addstr的前两个参数应该是row,col作为整数,但您正在传递列表:

要使正方形像这样:

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, '#')      
填充对角线的代码示例:

代码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)
运行:
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:从你们的代码看来,你们想填充对角线,所以我在后面编辑了正方形的答案

@Grijesh Chauhan,谢谢,如何突出这些部分?我想知道“工作”需要大写吗?你知道像眨眼、粗体这样的属性吗?检查下面我添加了颜色和粗体…@GrijeshChauhan,啊,你添加了背景色,这是我错过的,谢谢!在
init\u pair()
中,第三个参数用于bg color。太好了,第一个可以工作。我尝试了“范围内的x(23,42)和范围内的y(5,24)”:stdscr.addch(y,x,“#”)”但失败了。我猜你的是机器能理解的正确方式。@Mario我没有读太多关于它的书,但可能是一些坐标问题。尝试更改值。