将 wx.grid 传递给 wx.frame WX.python

pass wx.grid to wx.frame WX.python

我只想做 2 classes

1- 创建网格

2- 获取网格并将其放入 wx.notebook

所以基本上一个 class 制作网格另一个 class 将网格作为参数并将其添加到 wx.notebook

但我不断收到一条错误消息

    self.m_grid1 = wx.grid.Grid(self) TypeError: Grid(): arguments did not match any overloaded call:

overload 1: too many arguments overload 2: argument 1 has unexpected type 'reportGrid'

这里是调用网格 class 的代码 reportGrid

class reportGrid ():

def __init__( self, list):

    self.m_grid1 = wx.grid.Grid(self)
    self.m_grid1.Create(parent = None, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.WANTS_CHARS, name="Grid")
    # Grid
    self.m_grid1.CreateGrid( 7, 18 )
    self.m_grid1.EnableEditing( True )
    self.m_grid1.EnableGridLines( True )
    self.m_grid1.SetGridLineColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_WINDOWTEXT ) )
    self.m_grid1.EnableDragGridSize( True )
    self.m_grid1.SetMargins( 0, 0 )

    # Columns
    self.m_grid1.EnableDragColMove( False )
    self.m_grid1.EnableDragColSize( True )
    self.m_grid1.SetColLabelSize( 30 )
    self.m_grid1.SetColLabelAlignment( wx.ALIGN_CENTRE, wx.ALIGN_CENTRE )

    # Rows
    self.m_grid1.EnableDragRowSize( True )
    self.m_grid1.SetRowLabelSize( 80 )
    self.m_grid1.SetRowLabelAlignment( wx.ALIGN_CENTRE, wx.ALIGN_CENTRE )

    # Label Appearance
    self.m_grid1.SetColLabelValue(0, "Yield")
    self.m_grid1.SetColLabelValue(1, "64CU")
    self.m_grid1.SetColLabelValue(2, "Yield")
    self.m_grid1.SetColLabelValue(3, "60CU")
    self.m_grid1.SetColLabelValue(4, "Chain")
    self.m_grid1.SetColLabelValue(5, "Logic")
    self.m_grid1.SetColLabelValue(6, "Delay")
    self.m_grid1.SetColLabelValue(7, "BIST")
    self.m_grid1.SetColLabelValue(8, "CREST")
    self.m_grid1.SetColLabelValue(9, "HSIO")
    self.m_grid1.SetColLabelValue(10, "DC-Spec")
    self.m_grid1.SetColLabelValue(11, "HBM")
    self.m_grid1.SetColLabelValue(12, "OS")
    self.m_grid1.SetColLabelValue(13, "PS")
    self.m_grid1.SetColLabelValue(14, "Alarm")
    self.m_grid1.SetColLabelValue(15, "JTAG")
    self.m_grid1.SetColLabelValue(16, "Thermal IDD")
    self.m_grid1.SetColLabelValue(17, "Insuff Config")

    self.m_grid1.SetRowLabelValue(0, "Today")
    self.m_grid1.SetRowLabelValue(1, "WTD")
    self.m_grid1.SetRowLabelValue(2, "WW45")
    self.m_grid1.SetRowLabelValue(3, "WW44")
    self.m_grid1.SetRowLabelValue(4, "WW43")
    self.m_grid1.SetRowLabelValue(5, "Monthly")
    self.m_grid1.SetRowLabelValue(6, "QTD")
    # Cell Defaults
    for i in range(len(list)):
        for j in range(len(list[i])):
            self.m_grid1.SetCellValue(i,j, list[i][j])


    self.m_grid1.SetDefaultCellAlignment( wx.ALIGN_LEFT, wx.ALIGN_TOP )

这里的 class 将它作为参数并假设创建笔记本

class reportFrame ( wx.Frame ):

def __init__( self, parent , grid1):
    wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"Report", pos = wx.DefaultPosition, size = wx.Size( 7990,210 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

    self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )

    bSizer6 = wx.BoxSizer( wx.VERTICAL )

    self.m_notebook1 = wx.Notebook( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 )
    self.m_notebook1.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_INFOBK ) )

    self.m_panel2 = wx.Panel( self.m_notebook1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
    bSizer14 = wx.BoxSizer( wx.HORIZONTAL )

    bSizer14.Add( grid1, 0, wx.ALL, 5 )


    self.m_panel2.SetSizer( bSizer14 )
    self.m_panel2.Layout()
    bSizer14.Fit( self.m_panel2 )
    self.m_notebook1.AddPage( self.m_panel2, u"a page", False )
    self.m_panel3 = wx.Panel( self.m_notebook1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
    bSizer17 = wx.BoxSizer( wx.VERTICAL )

    bSizer17.Add( grid1, 0, wx.ALL, 5 )
    self.m_panel3.SetSizer( bSizer17 )
    self.m_panel3.Layout()
    bSizer17.Fit( self.m_panel3 )
    self.m_notebook1.AddPage( self.m_panel3, u"a page", True )

    bSizer6.Add( self.m_notebook1, 1, wx.EXPAND |wx.ALL, 3 )
    self.SetSizer( bSizer6 )
    self.Layout()

    self.Centre( wx.BOTH )
    self.Show(show=True)

wx.grid.Grid(self) 这里 self 必须是 wx.Window (或子类)类型。在您的代码中,它是 reportGrid 类型。

但是 reportGrid 不是 wx.Window 也不是 wx.Window 的子类。

如果您有 wx.Notebook 的页面 "pagegrid"(例如,类型 wx.Panel 或子类),那么您可以设置

class reportGrid (wx.Panel): 
def __init__( self, list):
    self.m_grid1 = wx.grid.Grid(self)

在你的笔记本定义中

pagegrid = reportGrid(nb)
nb.AddPage(pagegrid , "Grid Page")