2013-03-28 57 views
0

我試圖在curses中將一個窗口分割成幾個子窗口(使用derwin())。derwin()中的.addstr()奇怪的錯誤 - Python中的對象Curses

該代碼創建兩個子窗口,我可以添加一個字符串;第一個功能沒問題。第二個是幾乎完全一樣,但給了我一個錯誤,當我嘗試添加一個字符串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 

回答

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)更大。所以你得到了錯誤。

0

不能確定有關但它已經(如解釋者所指出的那樣)與字符串有關,並且它們在我創建的子窗口中沒有足夠的空間。