1

So I have been searching around but can't seem to find a solution to my problem. I would like to update the text of a QPushButton when it is clicked. Every time i run my code it crashes with no error message. Please Could someone help me? i have attached the relevant section of my code below:

def retranslateUi(self, MainWindow):
    _translate = QtCore.QCoreApplication.translate
    MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
    self.OuterSwitch.setText(_translate("MainWindow", "OuterDoorControl"))
    self.InnerSwitch.setText(_translate("MainWindow", "InnerDoorControl"))

...

class ControlMainWindow(QtWidgets.QMainWindow):
def __init__(self,parent=None):
    super(ControlMainWindow,self).__init__(parent)
    self.ui = Ui_MainWindow()
    self.ui.setupUi(self)

    self.ui.OuterSwitch.clicked.connect(self.OuterControl)
    self.ui.InnerSwitch.clicked.connect(self.InnerControl)


def OuterControl(self):
    if GPIO.input(Inner)==0: #InnerDoorOpen
        return GPIO.output(Outer,GPIO.HIGH),print("Please Close Inner Door")
    elif GPIO.input(Outer) ==1: #Outer Door Close
        self.OuterSwitch.setText(_translate("MainWindow","Close Outer Door"))
        QApplication.processEvents()
        return GPIO.output(Outer,GPIO.LOW) #Open Outer Door
    elif GPIO.input(Outer) == 0: #OuterDoor Open
        self.ui.InnerSwitch.setEnabled(False)
        QtCore.QTimer.singleShot(10000,partial(self.ui.InnerSwitch.setEnabled,True))
        return GPIO.output(Outer,GPIO.HIGH) #Close OuterDoor

The OuterSwitch and InnerSwitch are the objectnames for the two push buttons I am using. I am using PyQt5 and designed the Gui using QtDesigner. I am using Python 3.7.

Please can you help?

0

1 Answer 1

1

I managed to fix the problem by using this line of code:

elif GPIO.input(Outer) ==1: #Outer Door Close
    self.ui.OuterSwitch.setText(QtWidgets.QApplication.translate("MainWindow","Close Outer Door",None))
    QtWidgets.QApplication.processEvents()

I needed to select the correct API.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.