在wxpython中将工具栏小部件一个接一个地切换4次的逻辑是什么?

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

这里,我正在尝试在工具栏上单击以更改位图图像,

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再次等。
  • 循环重复。

[请帮助我解决此逻辑。

python wxpython wxwidgets
1个回答
0
投票
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
© www.soinside.com 2019 - 2024. All rights reserved.