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()
可笑容易。謝謝!我想我應該知道那.... –