Открытие окна через menubar

Пытаюсь реализовать открытие 2-го окна при нажатии на кнопку в menubar, но что-то идёт не так.

import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QAction, QWidget

lst = ["1", "2", "3", "4"]


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        about = QAction('&О программе', self)

        menu = self.menuBar()
        cpravka = menu.addMenu('&Справка')
        cpravka.self.addAction(about)

        self.setGeometry(300, 300, 800, 500)
        self.setWindowTitle('MainWindow')

        self.init_handlers()

    def init_handlers(self):  # обработка открытия 2 окна
        self.about.clicked.connect(self.show_window_2)

    def show_window_2(self):  # открытие 2  окна
        self.w2 = Window2()
        self.w2.show()


class Window2(QWidget):
    def __init__(self):
        super(Window2, self).__init__()
        self.setWindowTitle('Window2')


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = MainWindow()
    ex.show()
    sys.exit(app.exec_())

Ответы (1 шт):

Автор решения: S. Nick

Как вариант:

import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QAction, QWidget


class Window2(QWidget):
    def __init__(self):
        super(Window2, self).__init__()
        self.setWindowTitle('Window2')
        

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setGeometry(300, 300, 800, 500)
        self.setWindowTitle('MainWindow')
        
        self.initUI()

    def initUI(self):
        about = QAction('&О программе', self)

        menu = self.menuBar()
        
        cpravka = menu.addMenu('&Справка')                     # +++
        self.newAction = cpravka.addAction("О программе")      # +++
        cpravka.triggered.connect(self.show_window_2)          # +++ triggered !!!

    def show_window_2(self, action):  # открытие 2  окна
        if action == self.newAction:
            self.w2 = Window2()
            self.w2.show()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = MainWindow()
    ex.show()
    sys.exit(app.exec_())

введите сюда описание изображения

→ Ссылка