# Buggy code
def __init__(self, qt_viewer, *, show=True):
    self.qt_viewer = qt_viewer

    self._qt_window = QMainWindow()
    self._qt_window.setAttribute(Qt.WA_DeleteOnClose)
    self._qt_window.setUnifiedTitleAndToolBarOnMac(True)
    self._qt_center = QWidget(self._qt_window)

    self._qt_window.setCentralWidget(self._qt_center)
    self._qt_window.setWindowTitle(self.qt_viewer.viewer.title)
    self._qt_center.setLayout(QHBoxLayout())
    self._status_bar = QStatusBar()
    self._qt_window.setStatusBar(self._status_bar)

    self._add_menubar()

    self._add_file_menu()
    self._add_view_menu()
    self._add_window_menu()
    self._add_help_menu()

    self._status_bar.showMessage("Ready")
    self._help = QLabel("")
    self._status_bar.addPermanentWidget(self._help)

    self._qt_center.layout().addWidget(self.qt_viewer)
    self._qt_center.layout().setContentsMargins(4, 0, 4, 0)

    self._update_palette(qt_viewer.viewer.palette)

    self._add_viewer_dock_widget(self.qt_viewer.dockConsole)
    self._add_viewer_dock_widget(self.qt_viewer.dockLayerControls)
    self._add_viewer_dock_widget(self.qt_viewer.dockLayerList)

    self.qt_viewer.viewer.events.status.connect(self._status_changed)
    self.qt_viewer.viewer.events.help.connect(self._help_changed)
    self.qt_viewer.viewer.events.title.connect(self._title_changed)
    self.qt_viewer.viewer.events.palette.connect(
        lambda event: self._update_palette(event.palette)
    )

    if show:
        self.show()


# Traceback (AttributeError)
Traceback (most recent call last):
File "/Users/gbokota/Documents/projekty/napari/napari/components/viewer_model.py", line 418, in _toggle_theme
self.theme = theme_names[(cur_theme + 1) % len(theme_names)]
File "/Users/gbokota/Documents/projekty/napari/napari/components/viewer_model.py", line 130, in theme
self.palette = self.themes[theme]
File "/Users/gbokota/Documents/projekty/napari/napari/components/viewer_model.py", line 114, in palette
self.events.palette()
File "/Users/gbokota/Documents/projekty/napari/napari/utils/event.py", line 508, in __call__
self._invoke_callback(cb, event)
File "/Users/gbokota/Documents/projekty/napari/napari/utils/event.py", line 529, in _invoke_callback
cb_event=(cb, event),
File "/Users/gbokota/Documents/projekty/napari/napari/utils/event.py", line 523, in _invoke_callback
cb(event)
File "/Users/gbokota/Documents/projekty/napari/napari/_qt/qt_main_window.py", line 99, in <lambda>
lambda event: self._update_palette(event.palette)
AttributeError: 'Event' object has no attribute 'palette'

# Fixed code
def __init__(self, qt_viewer, *, show=True):
    self.qt_viewer = qt_viewer

    self._qt_window = QMainWindow()
    self._qt_window.setAttribute(Qt.WA_DeleteOnClose)
    self._qt_window.setUnifiedTitleAndToolBarOnMac(True)
    self._qt_center = QWidget(self._qt_window)

    self._qt_window.setCentralWidget(self._qt_center)
    self._qt_window.setWindowTitle(self.qt_viewer.viewer.title)
    self._qt_center.setLayout(QHBoxLayout())
    self._status_bar = QStatusBar()
    self._qt_window.setStatusBar(self._status_bar)

    self._add_menubar()

    self._add_file_menu()
    self._add_view_menu()
    self._add_window_menu()
    self._add_help_menu()

    self._status_bar.showMessage("Ready")
    self._help = QLabel("")
    self._status_bar.addPermanentWidget(self._help)

    self._qt_center.layout().addWidget(self.qt_viewer)
    self._qt_center.layout().setContentsMargins(4, 0, 4, 0)

    self._update_palette()

    self._add_viewer_dock_widget(self.qt_viewer.dockConsole)
    self._add_viewer_dock_widget(self.qt_viewer.dockLayerControls)
    self._add_viewer_dock_widget(self.qt_viewer.dockLayerList)

    self.qt_viewer.viewer.events.status.connect(self._status_changed)
    self.qt_viewer.viewer.events.help.connect(self._help_changed)
    self.qt_viewer.viewer.events.title.connect(self._title_changed)
    self.qt_viewer.viewer.events.palette.connect(self._update_palette)

    if show:
        self.show()