example:  

[![example](https://i.stack.imgur.com/4UMGv.png)](https://i.stack.imgur.com/4UMGv.png)

Let's say I have a MainWindow widget and inside that class, I instantiate two other widgets (widget one and widget two). Each widget will have a button: next and back for widget one and widget two respectively. The first widget is visible and the second one is hidden.

I would like to call a function inside the first widget that would hide it-self and show the second widget. Then the same thing for the second widget.

I could do this if I place the function and connect the buttons inside the main window but I would like to avoid that. I don't have a very good knowledge of signals and slots to know how do it or any other strategies then putting all the logic in the main window.

```
import sys
from PyQt5 import QtWidgets as qtw

class WidgetOne(qtw.QWidget):
    def __init__(self):
        super().__init__()
        ########
        # initialization
        ########
        self.layout = qtw.QVBoxLayout()
        self.setLayout(self.layout)
        ########
        # Buttons
        ########
        self.next_button = qtw.QPushButton('Next')
        self.next_button.clicked.connect(self.next_widget)
        ########
        # Layout
        ########
        self.layout.addWidget(self.next_button)

    def next_widget(self):
        self.hide()
        # widget_two.show() # <--- This part won't work

class WidgetTwo(qtw.QWidget):
    def __init__(self):
        super().__init__()
        ########
        # initialization
        ########
        self.layout = qtw.QVBoxLayout()
        self.setLayout(self.layout)
        ########
        # Buttons
        ########
        self.back_button = qtw.QPushButton('Back')
        self.back_button.clicked.connect(self.back_to_first_widget)
        ########
        # Layout
        ########
        self.layout.addWidget(self.back_button)
        self.hide()

    def back_to_first_widget(self):
        self.hide()
        # widget_one.show()  # This part won't work

class MainWindow(qtw.QWidget):
    def __init__(self):
        super().__init__()
        ########
        # initialization
        ########
        self.layout = qtw.QVBoxLayout()
        self.setLayout(self.layout)
        self.widget_one = WidgetOne()
        self.widget_two = WidgetTwo()

        ########
        # Layout
        ########
        self.layout.addWidget(self.widget_one)
        self.layout.addWidget(self.widget_two)
        self.setWindowTitle("Title")
        self.show()

if __name__ == '__main__':
    app = qtw.QApplication(sys.argv)
    mw = MainWindow()
    sys.exit(app.exec())

```