此源代码
class MyToolBar(wx.ToolBar):
def AddTool2(self, id, shortHelp = '', longHelp = ''):
global TB_SIZE
try:
ArtId = ArtMap.get(id)
Ico = wx.ArtProvider.GetBitmap(ArtId, wx.ART_TOOLBAR, TB_SIZE)
self.AddSimpleTool(id, Ico, shortHelp, longHelp)
except StandardError:
print('Something wrong, maybe wrong id')
Class MyFrame(wx.Frame):
def __init__(self, parent, *args, **kwargs):
wx.Frame.__init__(self, parent, *args, **kwargs)
ToolBar = MyToolBar(self)
ToolBar.AddTool2(wx.ID_NEW, 'New', 'Creates new file')
self.SetToolBar(ToolBar)
self.GetToolBar().Realize()
ArtMap = { wx.ID_NEW : wx.ART_NEW,
}
ID_BOUNCE = wx.NewId()
TB_SIZE = wx.Size(16,16)
app = wx.app()
frame = MyFrame(None, -1, 'MyFrame', (0,0))
app.MainLoop()
适用于在工具具有wx.ART时向工具栏添加工具。但是你如何添加一个没有wx.ART或没有wx.ART的新工具,它可以像ID_BOUNCE那样代表工具Bounce假设在框架中反弹球?
提前致谢。