简体   繁体   中英

How to pass arguments to a custom class in python?

How do I make the pass the Grid size ( self.CreateGrid(20,20) ) (number of rows and columns) to the custom class below?

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()
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()

And then instantiate it with:

GraphicsPage (someParent, 20, 30)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM