繁体   English   中英

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

[英]How to pass arguments to a custom class in python?

如何将Grid大小( 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()
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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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