How to make a wxpython Bitmap Button with only image and no extra pixels and border around image
python, wxpython, wxwidgets
Solution
You can directly use static bitmap and capture the mouse event in this bitmap.
try this:
sBitMap = wx.StaticBitmap(self._ribbon, -1, wx.Bitmap("image.png", wx.BITMAP_TYPE_ANY), (0, 0), (37,17))
sBitMap.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
def OnLeftDown(self, e):
print "OnLeftDown"
Edit:
Fetch the size from the source image and use it to create the static bitmap
sBitMap = wx.StaticBitmap(self._ribbon, -1, wx.Bitmap("image.png", wx.BITMAP_TYPE_ANY), (0, 0), (bmp.GetWidth(), bmp.GetHeight()))
Problem
I am trying to use an image as a button in wxpython. What I want is that there should only be a bitmap and no other border or any extra pixel around the button. I would really only want to capture a click on a bitmap, so maybe I do not need an actual button. "Pressing down" the button is hence not required. One option that I am using a PlateButton with platebutton.PB_STYLE_NOBG which works fine only when it is displaying the image without any mouse hover or clicks. Now when I hover the button, what I want is a shadowed image of same image(only image and no border or anything), but what I get is a square border around my image. My code : ``` import wx.lib.platebtn as platebutton imageButton = platebutton.PlateButton(self._ribbon,wx.ID_NEW, bmp = wx.Bitmap("image.png", wx.BITMAP_TYPE_ANY), pos = (0,0), size = (37,17), style= platebutton.PB_STYLE_DEFAULT | platebutton.PB_STYLE_NOBG) ```