-1

I want to call an existing instance from another class in to other class in Python but I don't know how to do this, help!

class ButtonSelectRetire(object):

    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):        

        cbr = ButtontRetire()
        cbr.off()     

class ButtontRetire(object):

    def __init__(self):
        self.enabled = True
        self.checked = False

    def onClick(self):
        pass

    def on (self):
        self.enabled = True

    def off (self):
        self.enabled = False
4

1 回答 1

0

也许您可以将 的实例传递ButtonRetire给 的构造函数ButtonSelectRetire

class ButtonSelectRetire(object):

  def __init__(self, button_retire):
    self.enabled = True
    self.checked = False
    self.button_retire = button_retire

  def onClick(self):        
    self.button_retire.off()


>>> buttonRetire = ButtonRetire()
>>> buttonSelectRetire = ButtonSelectRetire(buttonRetire)

实际上,据我了解,您想将信号连接buttonSelectRetire.onClick到回调buttonRetire.off()吗?

如果你在 PyQt4 程序中,这很容易做到:

self.buttonSelectRetire.onClick.connect(self.buttonRetire.off)
于 2013-07-19T16:03:48.353 回答