Why can't MenuBar get mouse events?

Hi there :wave:

Does anyone know the reason why MenuBar cannot get mouse events?
As the code bellow demonstrates,

import wx

class Frame(wx.Frame):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        panel = wx.Panel(self)

        menubar = wx.MenuBar()
        menu = wx.Menu()
        menuexit = menu.Append(wx.ID_EXIT, "Exit\tCtrl-q")
        self.Bind(wx.EVT_MENU, print, menuexit)

        menubar.Append(menu, "File")
        self.SetMenuBar(menubar)

        statusbar = wx.StatusBar(self)
        self.SetStatusBar(statusbar)

        def echo(v):
            print(v.EventObject)

        self.Bind(wx.EVT_CONTEXT_MENU, echo)
        panel.Bind(wx.EVT_CONTEXT_MENU, echo)
        menubar.Bind(wx.EVT_CONTEXT_MENU, echo)
        statusbar.Bind(wx.EVT_CONTEXT_MENU, echo)

        self.Bind(wx.EVT_LEFT_DOWN, echo)
        panel.Bind(wx.EVT_LEFT_DOWN, echo)
        menubar.Bind(wx.EVT_LEFT_DOWN, echo)
        statusbar.Bind(wx.EVT_LEFT_DOWN, echo)

app = wx.App()
frm = Frame(None)
frm.Show()
app.MainLoop()

every wx.Window objects such as the titlebar, statusbar, (maybe toolbar too?) and panel can get mouse events, but why not menubar?

could be because of this but I’m not sure about the details. There’s a lot going on about menus and event handling… it’s difficult to pinpoint a line of the source where it says, “here I’m just blocking mouse events because, reasons”.

1 Like

Thank you very much, ricpol.

I understood (or felt like so :sweat_smile: I’ve been away from programming with wxWidget for a quite long time) why it is impossible.
That’s what I wanted to know!