2011-05-11 72 views
2

我想將面板類添加到框架類中的sizer中,我將在代碼的主線中調用該框架類。將wxpython面板類添加到sizers

我得到的錯誤是TypeError: wx.Window, wx.Sizer, wx.Size, or (w,h) expected for item。我認爲這與面板類而不是面板類的實例有關。

無論哪種方式,我會怎麼做這樣的事情?

代碼如下:

#!/usr/bin/python 
# -*- coding: utf-8 -*- 

import wx 

class step_1(wx.Panel): 
    def __init__(self, parent): 
     wx.Panel.__init__(self, parent, id=wx.ID_ANY) 

     sizer = wx.BoxSizer(wx.VERTICAL) 
     txtOne = wx.TextCtrl(self, wx.ID_ANY, "") 

     sizer = wx.BoxSizer(wx.VERTICAL) 
     sizer.Add(txtOne, 0, wx.ALL, 5) 

     self.SetSizer(sizer) 

class step_2(wx.Panel): 
    def __init__(self, parent): 
     wx.Panel.__init__(self, parent, id=wx.ID_ANY) 

     sizer = wx.BoxSizer(wx.VERTICAL) 
     txtOne = wx.TextCtrl(self, wx.ID_ANY, "") 

     sizer = wx.BoxSizer(wx.VERTICAL) 
     sizer.Add(txtOne, 0, wx.ALL, 5) 

     self.SetSizer(sizer) 

class main_frame(wx.Frame): 
    """Main Frame holding the main panel.""" 
    def __init__(self,*args,**kwargs): 
     wx.Frame.__init__(self,*args,**kwargs) 
     p = wx.Panel(self) 
     sizer = wx.BoxSizer(wx.VERTICAL) 
     sizer.Add(step_1,0,border = 5) 
     sizer.Add(step_2,0,border = 5) 
     p.SetSizerAndFit(sizer) 
     self.Show() 

if __name__ == "__main__": 
    app = wx.App(False) 
    frame = main_frame(None,-1,size = (400,300)) 
    app.MainLoop() 

回答

3

就像你自己說:你不是在傳遞step_1step_2類的實例施膠機,其中當然,你應該是。簡單地創建它們的實例:

class main_frame(wx.Frame): 
    """Main Frame holding the main panel.""" 
    def __init__(self,*args,**kwargs): 
     wx.Frame.__init__(self,*args,**kwargs) 
     p = wx.Panel(self) 

     stp1 = step_1(p) 
     stp2 = step_2(p) 

     sizer = wx.BoxSizer(wx.VERTICAL) 
     sizer.Add(stp1, 0, border = 5) 
     sizer.Add(stp2, 0, border = 5) 
     p.SetSizerAndFit(sizer) 
     self.Show() 
+0

可笑容易。謝謝!我想我應該知道那.... –