Search code examples
pythonbuttonbitmapwxpythonborder

wxPython -- How to update the border style of BitmapButton in some event say click


I am trying to add/remove border of BitmapButton AFTER the button been created. I haven't find any working example to update the appearance of BitmapButton. Say

self.btn = wx.BitmapButton(self.panel, wx.ID_ANY, bmp, pos=(...))
self.Bind(wx.EVT_BUTTON, self.OnClick, self.btn)

Then in OnClick

def OnClick(self):
    # what should be here to give / remove the border of the button being clicked

Thanks


Solution

  • You need to use methods like SetWindowStyle() or SetWindowStyleFlag(), which are implemented by wx.Window, a common ancestor for all wxWidgets windows, and documented here.

    For example, for the border, try this:

    btn.SetWindowStyleFlag(wx.SIMPLE_BORDER)
    # or
    btn.SetWindowStyleFlag(wx.NO_BORDER)