如何在python中将参数传递给自定义类?

时间:2013-09-12 06:28:01

标签: python class wxpython arguments

如何将网格大小(self.CreateGrid(20,20))(行数和列数)传递给下面的自定义类?

import wx

class GraphicsPage(wx.grid.Grid):

    def __init__(self, parent): 
        wx.grid.Grid.__init__(self, parent, -1) 
        self.CreateGrid(20,20) 

        self.SetRowLabelSize (0) 
        self.SetMargins(0,0) 
        self.AutoSizeColumns(False) 
        self.ForceRefresh()

1 个答案:

答案 0 :(得分:3)

import wx

class GraphicsPage(wx.grid.Grid):

    def __init__(self, parent, width, height): 
        super(GraphicsPage, self).__init__(parent, -1) 
        self.CreateGrid(width, height) 

        self.SetRowLabelSize (0) 
        self.SetMargins(0,0) 
        self.AutoSizeColumns(False) 
        self.ForceRefresh()

然后用:

实例化它
GraphicsPage (someParent, 20, 30)