WxPython更改按钮面板上的按钮(位图)

问题描述 投票:0回答:1

使用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()
wxpython
1个回答
1
投票

使用正常的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'))
© www.soinside.com 2019 - 2024. All rights reserved.