The wx.BitmapButton shows an image, great for those folks who think that a picture is worth a thousand words. The snippet gives an example how to load the image, size the button, and put the image on the the button.
# Example of a wxPython Frame, Panel and BitmapButton # wx.BitmapButton(parent, id, bitmap, pos = wx.DefaultPosition, size = wx.DefaultSize, style=0) # best to size the button to the image width and height plus a border margin # tested with Python24 and wxPython26 vegaseat 22jun2006 import wx class MyFrame(wx.Frame): """make a frame, inherits wx.Frame, add a panel and button""" def __init__(self): # create a frame, no parent, default to wxID_ANY wx.Frame.__init__(self, None, wx.ID_ANY, 'wxBitmapButton', pos=(300, 150), size=(300, 350)) # panel needed to display button correctly self.panel1 = wx.Panel(self, -1) # pick a button image file you have (.bmp .jpg .gif or .png) imageFile = "Btn_down.jpg" image1 = wx.Image(imageFile, wx.BITMAP_TYPE_ANY).ConvertToBitmap() self.button1 = wx.BitmapButton(self.panel1, id=-1, bitmap=image1, pos=(10, 20), size = (image1.GetWidth()+5, image1.GetHeight()+5)) self.button1.Bind(wx.EVT_BUTTON, self.button1Click) # show the frame self.Show(True) def button1Click(self,event): self.SetTitle("Button1 clicked") # test application = wx.PySimpleApp() # call class MyFrame window = MyFrame() # start the event loop application.MainLoop()
Hi and thank you very much for posting your code. Helps a lot ! One question though : is there a way to update the image on the button once created and displayed ?
I'm writing a small application that display the weather. Every hour, I would like to update the information. I'm able to do it for text using ChangeValue on a TextCtrl but cannot find anything to update the 'weather image' that I have positionned on a BitmapButton. Any idea ?
Thank a lot.
Are you able to help answer this sponsored question?
Questions asked by members who have earned a lot of community kudos are featured in order to give back and encourage quality replies.
I want to write out a DXF file with line arc and maybe spline.
My issue is documentation; While I have looked at AutoCAD's site I feel that there isnt ...
How to connect device scanner with visual basic, its analogy I made button scan in vb and typing button scan in press scanner live and walk .. how? Help ...
For Each ctrl As Control In Me.Controls("pnlMainPanel").Controls If ctrl.GetType Is GetType(System.Windows.Forms.Panel) Then For Each subCtrl As Control In ctrl.Controls If subCtrl.GetType Is GetType(System.Windows.Forms.TextBox) Then MsgBox(subCtrl.Text) End If If subCtrl.GetType Is ...