在这里,我试图在工具栏单击时更改位图图像,img = wx.Image('Image_A Path Here').Scale(50, 33, wx.IMAGE_QUALITY_HIGH)face_tool = self.toolbar.AddTool(6, 'Animation', wx.Bitmap(img), 'Change Face Image')self.on_face_click(None, init_face=True)self.Bind(wx.EVT_TOOL, self.on_face_click, face_tool)def on_face_click(self, event, init_face=False): if init_face: self.Test_face_click = False else: self.Test_face_click = not self.Test_face_click if self.Test_face_click: img = "Image_B Path Here" png = wx.Image(img, wx.BITMAP_TYPE_ANY).ConvertToBitmap() self.bottomToolbar.SetToolNormalBitmap(id=6, bitmap=png) else: img = "Image_A Path Here" png = wx.Image(img, wx.BITMAP_TYPE_ANY).ConvertToBitmap() self.bottomToolbar.SetToolNormalBitmap(id=6, bitmap=png)我想在每次点击事件中一个接一个地更改位图图像 4 次。假设默认图像是 image_A,然后在第一次单击 (on_face_click) 事件时我想将位图更改为 image_B,然后在第二次单击时它应该更改为 image_C,然后在第三次单击时将其更改为 image_C,然后在第四次单击时将其更改为 image_A等等循环重复。请帮我解决这个逻辑。
1 回答

30秒到达战场
TA贡献1828条经验 获得超6个赞
self.btnImages= [ 'path of image_B', 'path of image_C','path of image_D','path of image_A']
self.img_index = 0
img = wx.Image('Image_A Path Here').Scale(55, 35, wx.IMAGE_QUALITY_HIGH)
b_face_tool = self.bottomToolbar.AddTool(id=6, 'Animation', wx.Bitmap(img))
self.Bind(wx.EVT_TOOL, self.on_face, b_face_tool)
def on_face(self, event):
if (self.img_index == len(self.btnImages)):
self.img_index = 0
img = self.btnImages[self.img_index]
self.bottomToolbar.SetToolNormalBitmap(id=6, bitmap=wx.Image(img, wx.BITMAP_TYPE_ANY).ConvertToBitmap())
self.img_index = self.img_index + 1
添加回答
举报
0/150
提交
取消