0

我正在尝试将curses中的一个窗口分割成几个子窗口(带有derwin())。

该代码创建了两个子窗口,我可以添加一个字符串;第一个功能没问题。第二个几乎完全相同,但是当我尝试添加一个字符串时给我一个错误addstr()

class Window(GUI):
'''
Window-object
'''

def __init__(self, y_max , x_max, y_pos , x_pos, Target, screen):
    self.Win_Count = 0
    self.y_pos = y_pos
    self.x_pos = x_pos
    self.y_max = y_max
    self.x_max = x_max
    self.parent = screen 
    self.Target = Target

    #Window-Objects
    self.Win = self.create_win_parent(y_pos)
    self.Name_Win = self.create_name_win(self.Win)
    self.IP_Win = self.create_ip_win(self.Win)

def create_win_parent(self, y_pos):
    y_size = 1
    x_size = self.x_max - self.x_pos
    new_win_obj = self.parent.derwin(y_size, x_size, self.y_pos, 0)
    self.Win_Count += 1
    return new_win_obj

def create_name_win(self, Win_Obj):
    x = Win_Obj.derwin(1,40, 0,0)
    x.box()
    x.addstr(0,5," CUSTOMER NAME ")
    return x

def create_ip_win(self, Win_Obj):
    x = Win_Obj.derwin(1,15, 0,41)
    x.box()
    x.addstr(0,5," IP-ADDRESS ")
    return x

我收到这个模糊的错误:

    Traceback (most recent call last):
  File "./2pollng.py", line 229, in <module>
    wrapper(main)                    # Enter the main loop
  File "/usr/lib/python2.6/curses/wrapper.py", line 43, in wrapper
    return func(stdscr, *args, **kwds)
  File "./2pollng.py", line 222, in main
    Main_App.Run(screen)
  File "./2pollng.py", line 106, in Run
    self.Create_Win(self.Inv.index(e), e)
  File "./2pollng.py", line 90, in Create_Win
    Win_Obj = Window(self.y_max, self.x_max, y_pos, x_pos, Target_x, self.screen)
  File "./2pollng.py", line 141, in __init__
    self.IP_Win = self.create_ip_win(self.Win)
  File "./2pollng.py", line 160, in create_ip_win
    x.addstr(0,5," IPADDRESS ")
_curses.error: addstr() returned ERR
4

2 回答 2

2
def create_ip_win(self, Win_Obj):
    x = Win_Obj.derwin(1,15, 0,41)
    x.box()
    x.addstr(0,5," IP-ADDRESS ")
    return x

在这个函数Win_Obj.derwin(1,15, 0,41)中显示 x-pos 应该在 0 和 14 之间。而在代码中addstr(0,5," IP-ADDRESS ")x 从 5 开始并且字符串的长度" IP-ADDRESS "大于(15-5)。所以你得到了错误。

于 2013-12-03T13:04:02.753 回答
0

不太确定具体细节,但它(如解释器所示,duh)与字符串有关,并且它们在我创建的子窗口中没有足够的空间。

于 2013-05-13T14:07:03.067 回答