Home > OS >  PyQT5 Clear form button wont clear anything
PyQT5 Clear form button wont clear anything

Time:08-11

I am trying to create a clear entire form button but I cant seem to get anything to clear at all, I've tried so many combinations and different things online but I can't seem to get anything to clear when I press the clear button nothing happens no matter which form ive used to try and change the code it just wont clear and for some reasons different types of clear functions will cause the continue button (which isnt set to do anything at this time) will crash the whole program hahaha. Any help is greatly appreciated :)

        self.clearButton = QtWidgets.QPushButton(self.centralwidget, clicked= lambda: clearButton())
        self.clearButton.setGeometry(QtCore.QRect(520, 610, 75, 23))
        self.clearButton.setObjectName("clearButton")
        self.continueButton = QtWidgets.QPushButton(self.centralwidget)
        self.continueButton.setGeometry(QtCore.QRect(200, 610, 75, 23))
        self.continueButton.setObjectName("continueButton")
        

        def clearButton():
            self.clearButton.clicked.connect(self.plainTextEdit.clear)

    

CodePudding user response:

So after looking at a program written by John Elder from codemy and testing his code i finally got it to work with the following code.

self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget, clicked=lambda: self.clear_it())
self.pushButton_2.setGeometry(QtCore.QRect(200, 610, 75, 23))
self.pushButton_2.setObjectName("pushButton_2")

This function is clearing properly.

def clear_it(self):
    self.plainTextEdit_2.clear()
    self.plainTextEdit.clear()
    self.plainTextEdit_4.clear()
    self.plainTextEdit_5.clear()
    self.plainTextEdit_6.clear()
    self.plainTextEdit_7.clear()
    self.plainTextEdit_8.clear()
    self.plainTextEdit_9.clear()
    self.dataBackupNameTextbox.clear()
    self.comboBox.setCurrentIndex(0)
    self.comboBox_2.setCurrentIndex(0)
  • Related