{Python: Stacked Widgets} next button not working (trying to switch widgets)

39 views Asked by At

I am trying to set up stacked widgets. I have a main page and I am trying to go to the next page which will be part of my stacked widgets. I am trying to switch to next page with a pushButton_2 named "Next". I set up my second page to be QtWidget but it just does not show up when I click the button. My code looks something like:


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.setStyleSheet("background-color: lightyellow;")

        self.stacked_widgets = QStackedWidget(self.ui.centralwidget)
        self.xyz_page = Ui_xyz()
       
        self.stacked_widgets.addWidget(self.xyz)

    
        #Next Button
        self.ui.pushButton_2.clicked.connect(self.on_next_button_clicked)

        def on_next_button_clicked(self):
        # Check the status of the checkboxes
        passive = self.ui.checkBox_2.isChecked()
        active = self.ui.checkBox.isChecked()

        # Determine which page to show based on the checkbox status
        if passive:
            # Show efficiency page if checkbox is checked
            self.stacked_widgets.setCurrentWidget(self.xyz)
        else:
            # Show the default page (welcome page) if the checkbox is not checked
            self.stacked_widgets.setCurrentWidget(self.ui.centralwidget)

I tried having it in a stacked layot- not working. I tried different variantions when I use self or no self- I am an idiot and didn't know what it does. I don't know what else to try

0

There are 0 answers