Радиокнопки и операторы if-elif не работают? [закрыто]

У меня есть 4 радиокнопки, и каждой из них даны разные имена.

They are put inside a button group. When the user selects a radio button, I want to store a certain value. Different radio button options that are clicked will lead to different values being stored. After checking the "Accomodation" checkbox & clicking a radio button, the "Next" button will also be enabled.

However, it seems that when I run the program, the if-elif blocks (that will carry out the operations as stated above) were not executed?

After I check the checkbox & selected a radio button and wanted to click the "Next" button, it was still disabled. I could not go to the next window.

The print ("hello") or print (3) etc. statements that I've put into the if-elif blocks (for debugging purposes) were not working when I clicked on the radio buttons.

My code are as below:

      self.stayInput.stateChanged.connect(self.showStay)  # when accommodation option is clicked
      def showStay(self):
    if self.stayInput.isChecked():  # if user wants to book accommodation

        self.stayChecked = 1
        self.pb_next2.setEnabled(False)  # since user says wants to book accommodation, must select a star before
        # proceeding

        # set radio buttons to visible
        self.rbStay1.setVisible(True)
        self.rbStay2.setVisible(True)
        self.rbStay3.setVisible(True)
        self.rbStay4.setVisible(True)

        if self.rbStay1.isChecked():  # if user choose 2 star
            print("hello")
            self.stayStars = 2
            self.pb_next2.setEnabled(True)
            print(2)

        elif self.rbStay2.isChecked():  # if user choose 3 star
            self.stayStars = 3
            self.pb_next2.setEnabled(True)
            print(3)

        elif self.rbStay3.isChecked():  # if user choose 4 star
            self.stayStars = 4
            self.pb_next2.setEnabled(True)
            print(4)

        elif self.rbStay4.isChecked():  # if user choose 5 star
            self.stayStars = 5
            self.pb_next2.setEnabled(True)
            print(5)

    else:  # if user doesn't want to book accommodation
        self.stayChecked = 0
        self.pb_next2.setEnabled(True)

        # set radio buttons to invisible
        self.rbStay1.setVisible(False)
        self.rbStay2.setVisible(False)
        self.rbStay3.setVisible(False)
        self.rbStay4.setVisible(False)

        checked = self.buttonGroup.checkedButton()

        if checked:
            self.buttonGroup.setExclusive(False)
            checked.setChecked(False)
            self.buttonGroup.setExclusive(True)

0 ответов

Другие вопросы по тегам