strange menu event generated by panel
- windows LTSC 2019
- Python 3.7.9
- wxPython 4.2.0 msw (phoenix) wxWidgets 3.2.0
import wx
class Frame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent)
panel = wx.Panel(self)
self.Bind(wx.EVT_MENU, self.OnMenu)
def OnMenu(self, event):
print(event.GetId()) # 1
print(event.GetEventObject()) # <wx._core.Panel object at 0x00000210DF4FA318>
class App(wx.App):
def OnInit(self):
frame = Frame(None)
frame.Center()
frame.Show()
return super().OnInit()
def main():
app = App()
app.MainLoop()
if __name__ == '__main__':
main()
run and press Enter, Frame will receive a menu event generated by Panel, why?
EVT_MENU is a command event (from the docu)
Note that CommandEvents and CommandEvent-derived event classes by default and unlike other Event-derived classes propagate upward from the source window (the window which emits the event) up to the first parent which processes the event. Be sure to read How Events Propagate Upwards.
EVT_MENU is a command event (from the docu)
Note that CommandEvents and CommandEvent-derived event classes by default and unlike other Event-derived classes propagate upward from the source window (the window which emits the event) up to the first parent which processes the event. Be sure to read How Events Propagate Upwards.
What puzzles me is that there is no menubar, but press key triggers a menu event
well, you may (or may not) be surprised how many events are going through the system! the logic is the other way round: you Bind those events you are interested in..
@daidai-up
return super().OnInit()
should be
return True