你可以这样做。
import wx
class TestFrame(wx.Frame):
def __init__(self, *args, **kwargs):
super(TestFrame, self).__init__(*args, **kwargs)
menubar = wx.MenuBar()
self.SetMenuBar(menubar)
menuFile = wx.Menu()
self.menuSave = menuFile.Append(-1, 'Save', 'Save Document')
self.menuClose = menuFile.Append(-1, 'Close', 'Close Application')
menubar.Append(menuFile, '&File')
self.Bind(wx.EVT_MENU, self.onMenu)
panel = wx.Panel(self)
pSizer = wx.BoxSizer(wx.VERTICAL)
panel.SetSizer(pSizer)
vSizer = wx.BoxSizer(wx.VERTICAL)
vSizer.Add(panel, 1, wx.EXPAND)
self.SetSizer(vSizer)
self.Layout()
def onMenu(self, event):
menuId = event.Id
if menuId == self.menuSave.Id:
print 'menuSave'
elif menuId == self.menuClose.Id:
print 'menuClose'
if __name__ == '__main__':
wxapp = wx.App(False)
testFrame = TestFrame(None)
testFrame.Show()
wxapp.MainLoop()