在 wxpython 中一个接一个地切换工具栏小部件 4 次的逻辑是什么?
what is the logic to toggle toolbar widget 4 times one after the other in wxpython?
在这里,我尝试更改工具栏上单击的位图图像,
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,然后在第 3 次单击将其更改为 image_C,然后在第 4 次单击再次将其更改为 image_A 等
- 循环重复。
请帮我解决这个逻辑。
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
在这里,我尝试更改工具栏上单击的位图图像,
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,然后在第 3 次单击将其更改为 image_C,然后在第 4 次单击再次将其更改为 image_A 等
- 循环重复。
请帮我解决这个逻辑。
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