1、main.py
#!/usr/bin/env python
#Boa:App:BoaApp
import wx
import mainFrame
modules ={'mainFrame': [1, 'Main frame of Application', 'mainFrame.py']}
class BoaApp(wx.App):
def OnInit(self):
self.main = mainFrame.create(None)
self.main.Show()
self.SetTopWindow(self.main)
return True
def main():
application = BoaApp(0)
application.MainLoop()
if __name__ == '__main__':
main()
2、mainFrame.py
关键:
1、wx.MenuItem才有菜单事件
2、self.Bind( wx.EVT_MENU, self.dostart, id = self.oper_start_item.GetId() )
# -*- coding: utf-8 -*-
import wx
def create(parent):
return mainFrame(parent)
class mainFrame ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"截屏专家", pos = wx.DefaultPosition, size = wx.Size( 508,319 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
self.mf_menubar = wx.MenuBar( 0 )
self.oper_menu = wx.Menu()
self.oper_start_item = wx.MenuItem( self.oper_menu, wx.ID_ANY, u"启动", wx.EmptyString, wx.ITEM_NORMAL )
self.oper_menu.AppendItem( self.oper_start_item )
self.oper_stop_item = wx.MenuItem( self.oper_menu, wx.ID_ANY, u"终止", wx.EmptyString, wx.ITEM_NORMAL )
self.oper_menu.AppendItem( self.oper_stop_item )
self.mf_menubar.Append( self.oper_menu, u"操作" )
self.set_menu = wx.Menu()
self.set_sys_item = wx.MenuItem( self.set_menu, wx.ID_ANY, u"系统设置", wx.EmptyString, wx.ITEM_NORMAL )
self.set_menu.AppendItem( self.set_sys_item )
self.mf_menubar.Append( self.set_menu, u"设置" )
self.help_menu = wx.Menu()
self.mf_menubar.Append( self.help_menu, u"帮助" )
self.SetMenuBar( self.mf_menubar )
self.mf_statusBar = self.CreateStatusBar( 1, wx.ST_SIZEGRIP, wx.ID_ANY )
mf_sizer = wx.BoxSizer( wx.HORIZONTAL )
self.SetSizer( mf_sizer )
self.Layout()
self.Centre( wx.BOTH )
# Connect Events
self.Bind( wx.EVT_MENU, self.dostart, id = self.oper_start_item.GetId() )
def __del__( self ):
pass
# Virtual event handlers, overide them in your derived class
def dostart( self, event ):
print 'sdfsdf'