1

I am trying to simulate a button click of a bitmap button. The code throws no errors and does nothing...

self.buttonImage = wx.Bitmap(button_image, wx.BITMAP_TYPE_PNG)
self.button = wx.BitmapButton(self, -1, self.buttonImage, pos=(100, 300), style = wx.NO_BORDER)

evt = wx.PyCommandEvent(wx.EVT_BUTTON.typeId, self.button.GetId())
wx.PostEvent(self, evt)
user3071933
  • 187
  • 1
  • 3
  • 10

1 Answers1

1

A matching answer has been given already in another post. Assuming you are in the same thread (which should be the most common case in wxPython) you have to replace the self in PostEvent with something relating to the button. And of course your posted event will result in nothing, because you did not bind an event to the bitmap button.

# button creation
self.button = wx.BitmapButton(pnl, -1, self.buttonImage, pos=(100, 300), style=wx.NO_BORDER)
# Bind an event
self.button.Bind(wx.EVT_BUTTON, self.on_btn)

# GUI test code
testbtn = frm.button # the button to be tested
evt = wx.PyCommandEvent(wx.EVT_BUTTON.typeId, testbtn.GetId())
wx.PostEvent(testbtn, evt) # try frm instead of testbtn and it will not work
Community
  • 1
  • 1
nepix32
  • 3,012
  • 2
  • 14
  • 29