先添加菜单项File-Open
self.m_menubar1 = wx.MenuBar( 0 ) self.mFile = wx.Menu() self.miOpen = wx.MenuItem( self.mFile, wx.ID_ANY, u"&Open"+ u"\t" + u"Ctrl+O", u"Open a project", wx.ITEM_NORMAL ) self.miOpen.SetBitmap( wx.Bitmap( u"pics/open.jpg", wx.BITMAP_TYPE_ANY ) ) self.mFile.AppendItem( self.miOpen )
然后添加toolbar项目,对应的tool item使用相应的菜单项ID,这个很重要
self.m_toolBar2 = self.CreateToolBar( wx.TB_HORIZONTAL, wx.ID_ANY ) self.m_toolBar2.AddLabelTool( self.miOpen.GetId(), u"Open", wx.Bitmap( u"pics/open.jpg", wx.BITMAP_TYPE_ANY ), wx.NullBitmap, wx.ITEM_NORMAL, u"Open a project", u"Open a project", None )
最后在事件绑定时只需要对同一个ID绑定一次即可
self.Bind( wx.EVT_MENU, self.OnOpen, id = self.miOpen.GetId() )
No comments :
Post a Comment