使用wx.lib.agw.buttonpanel
创建了我的第一个按钮面板。
它有很多按钮,我需要在特定事件上更改特定按钮的图像,我该怎么做?目前我重新创建整个面板,寻找更好的方法。
我在这里如何创建它们:
for count, png in enumerate(self.pngs):
shortHelp = short_help[count]
kind = wx.ITEM_NORMAL
longHelp = long_help[count]
btn = bp.ButtonInfo(self.titleBar, wx.NewId(),
png[0], kind=kind,
shortHelp=shortHelp)
self.titleBar.AddButton(btn)
self.Bind(wx.EVT_BUTTON, OnButtonFunc[count], id=btn.GetId())
self.titleBar.AddSeparator()
使用正常的wx.BitmapButton
,您可以使用event
来更改图像。我不知道你是否会用wx.lib.agw.buttonpanel
获得相同的里程数。
您将需要存储图像以交换到按钮的Id
,然后使用事件交换图像。
def MyButtonFunction(self, event):
ButtonId = event.GetId()
#Map the Id to the image here#
event.GetEventObject().SetBitmap(wx.Bitmap('/path/to/button/image/swap.png'))