简体   繁体   English

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

[英]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? 如何将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()

And then instantiate it with: 然后使用以下方法实例化它:

GraphicsPage (someParent, 20, 30)

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

相关问题 如何将参数传递给python fabric自定义任务 - how to pass arguments to a python fabric custom task Python传递基类的参数 - Python pass arguments of base class 如何将参数传递给 Python 3 中的自定义静态类型提示? - How do I pass arguments to custom static type hints in Python 3? 如何将其他参数传递给自定义python排序功能 - How to pass additional arguments to custom python sorting function 如何在 Python 中创建同一个类的多个实例并传递不同的参数 - How to create multiple instances of a same class and pass different arguments in Python 在Python实例化一个class到function时,如何传递arguments? - How to pass arguments when instantiating a class to a function in Python? 如何从Python 3.x中的类定义传递参数到元类? - How to pass arguments to the metaclass from the class definition in Python 3.x? 如何创建多个 class 对象并在 Python 中使用循环传递 arguments? - How to create multiple class objects and pass arguments with loop in Python? 如何将argparse参数传递给类 - how to pass argparse arguments to a class 如何将参数传递给类中的装饰器 - how to pass arguments to a decorator in a class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM