在python中从它们内部的方法连接三个类

时间:2016-06-07 14:11:18

标签: python matplotlib pyqt

我正在使用PyQt创建一个带有matplotlib的应用程序,我正在尝试将一个类中的方法与另一个类中的另一个方法连接起来。

A类是QMainWindow,它实例化class B,这是matplotlib数字。因此,当我从a调用方法class A(连接到QPushButton)时,它会调用class C来执行某些操作,然后它必须连接到method bclass B中做其他事情。

我读了很多编码,我发现了这个例子:

python super calling child methods

我试图这样做,但它没有用。

这是我的代码:

class A(QMainWindow):
  def __init__(self):
    super(QMainWindow, self).__init__()
    #A lot of stuff in here

    #I instantiate class B
    self.call_B = B()

  def a(self):
    print "Hello"
    self.open_C = C(self)

class B(QMainWindow):
  def __init__(self):
    QMainWindow.__init__(self)
    #A lot of stuff in here

  def b(self):
    print "How are you?"

class C(B):
  def __init__(self):
    super(C, self).__init__()
    #A lot of stuff in here

    self.connect_to_b()      

  def connect_to_b(self):
    #From here is where I need to call method b() from class B  

如上所示,我需要将connect_to_b中的方法class Cb中的方法class B相关联。

我怎样才能做到这一点?希望你能帮帮我。

1 个答案:

答案 0 :(得分:1)

ExtAudioFileSetProperty(testRecordFile, kExtAudioFileProperty_ClientDataFormat, s, &asbd); 继承自C,因此B可以访问connect_to_b

b