为什么我不能在某个类中调用该函数

时间:2019-07-30 15:22:29

标签: python pyqt5

我目前有一个打开主窗口,然后在单击按钮时打开第二个窗口的项目。 Main窗口类很好,并且可以调用其中的函数,而第二个窗口仍可以显示其UI,但不能调用它的函数(第二个窗口中的按钮未调用应调用的函数)。有什么我想念的吗?

class MainWindow():
    def __init__(self, dlg):
        self.dlg = dlg
        dlg.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint | QtCore.Qt.WindowCloseButtonHint)

        dlg.systemBase.setText(make_prefix(Sbase)+"VA")

        dlg.comboBox.currentTextChanged.connect(self.Calc)
        dlg.comboBox.addItem(str(380.00/1e3))
        dlg.comboBox.addItem(str(400.00/1e3))
        dlg.comboBox.addItem(str(220.00/1e3))


        dlg.lineEdit_3.setPlaceholderText("Accepts 1-10")
        dlg.lineEdit_3.setValidator(QIntValidator(1,10))
        dlg.lineEdit_3.textChanged.connect(self.disableButton)


        dlg.comboBox_2.addItem("Single Phase")
        dlg.comboBox_2.addItem("3 Phase")

        dlg.pushButton_3.setDisabled(True)
        dlg.pushButton_3.clicked.connect(self.selectPhase)
        dlg.lineEdit_3.setFocus()
        dlg.lineEdit_3.returnPressed.connect(self.selectPhase)
        dlg.show()
        app.exec()

    def Calc(self):
        Vbase=float(self.dlg.comboBox.currentText())
        currentBase = ((Sbase)/ (math.sqrt(3) * (Vbase*1e3)))
        dlg.currentBase.setText(str(make_prefix(currentBase))+"A")
        baseImpedance = (((Vbase*1e3)*(Vbase*1e3)) / (Sbase))
        dlg.baseImpedance.setText(str(make_prefix(baseImpedance))+" p.u.")


    def selectPhase(self):
        Nbus = dlg.lineEdit_3.text()
        if Nbus == "1":
            self.SW = uic.loadUi("try1.ui")
            SecondWindow(self.SW) #calling the second window
        else:
            print("try again")


        print(int(Nbus))
        if self.dlg.comboBox_2.currentText() == "Single Phase":
            print("u selected single phase")

        else:
            print("u selected 3 phase")


    def disableButton(self):
        if len(self.dlg.lineEdit_3.text()) > 0:
            dlg.pushButton_3.setDisabled(False)
        else:
            dlg.pushButton_3.setDisabled(True)


class SecondWindow():
    def __init__(self, SW):
        self.SW = SW

        #Button
        SW.pushButton.setText("Calculate")
        SW.pushButton.clicked.connect(self.tst) #nothing happens in clicking the button. 
        SW.show()
    def tst(self): 
        print("testing")


if __name__ == '__main__':
    app = QtWidgets.QApplication([])
    dlg=uic.loadUi("try.ui")
    MainWindow(dlg)

我希望从SecondWindow类在tst()函数内打印字符串。

0 个答案:

没有答案