Core Windows/Controls → BitmapButton
Overview = """\
A BitmapButton control displays a bitmap. It can have a separate bitmap for each button state: normal, selected, disabled.
The bitmaps to be displayed should have a small number of colours, such as 16,
to avoid palette problems.
A bitmap can be derived from most image formats using the wx.Image class.
"""
import wx
class Frame(wx.Frame):
def __init__(self, parent, id=-1, title='BitmapButton', pos=wx.DefaultPosition,
size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE
):
wx.Frame.__init__(self, parent, id, title, pos, size, style)
Panel = wx.Panel(self, -1)
Bitmap = wx.Bitmap('SPALDING.jpg', type=wx.BITMAP_TYPE_ANY)
Button = wx.BitmapButton(Panel, -1, Bitmap, (20, 20), (Bitmap.GetWidth()+10, Bitmap.GetHeight()+10))
# Additional number of 10 brings BitmapButton 3D look!
Button.SetToolTipString('This is a bitmap button.')
self.Bind(wx.EVT_BUTTON, self.OnTest, Button)
Button = wx.BitmapButton(Panel, -1, Bitmap, (20, 300), style=wx.NO_BORDER)
Button.SetToolTipString('This is a bitmap button with wx.NO_BORDER')
self.Bind(wx.EVT_BUTTON, self.OnTest, Button)
def OnTest(self, event):
wx.MessageBox('You have clicked wx.BitmapButton.', 'Prompt')
def TestFrame():
app = wx.PySimpleApp()
frame = Frame(parent=None)
frame.Centre()
frame.Show()
app.MainLoop()
if __name__ == '__main__':
TestFrame()