wxPython -- 如何在某些事件中更新 BitmapButton 的边框样式,例如单击

Wen*_*ndy 2 python wxpython border bitmap button

我正在尝试在创建按钮后添加/删除 BitmapButton 的边框。我还没有找到任何工作示例来更新 BitmapButton 的外观。说

self.btn = wx.BitmapButton(self.panel, wx.ID_ANY, bmp, pos=(...))
self.Bind(wx.EVT_BUTTON, self.OnClick, self.btn)
Run Code Online (Sandbox Code Playgroud)

然后在 OnClick

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

谢谢

Yir*_*kha 5

您需要使用SetWindowStyle()或 之类的方法SetWindowStyleFlag(),这些方法由wx.Window所有 wxWidgets 窗口的共同祖先实现,并记录在此处

例如,对于边框,试试这个:

btn.SetWindowStyleFlag(wx.SIMPLE_BORDER)
# or
btn.SetWindowStyleFlag(wx.NO_BORDER)
Run Code Online (Sandbox Code Playgroud)