First a couple notes about posting:
you sample app is a perfect test case. However:
- it's generally better to enclose the code, rather than putting it
straight into email -- clients tend to add wrapping, etc that messes
things up.
- please enclose the pngs as well (as long as they are small) the
goal it to make it as easy as possible for us to run your code to test
it.
Now the real question:
On my system OS-X, it works fine -- that may be a platform difference.
I think you may not be able to use a StaticBitmap -- behaviour of
overlapping widgets is a bit undefined. An alternative is to do the
drawing in EVT_ERASE_BACKGROUND -- see sample enclosed.
By the way, you are right to put a panel in there, but things get
confusing if you put that in the frame class directly -- what do you
bind events, to, etc... So I put all this in wx.Panel subclass, then
put that on a frame to demo it.
See:wxPython Style Guide - wxPyWiki
NOTE: this is example is very basic -- you are likely to wan to be
more careful with making sure the background image is the right size,
maybe checking for the "damaged region", and only drawing that,
etc....
some googling will help you find more examples.
Come to think of it, has no one written and contributed a mature
"Panel with a background Image"? -- we get enough questions on here
aboutit, we should.
-Chris
On Thu, Feb 2, 2012 at 8:31 PM, kevinlcarlson <kevinlcarl...@gmail.com> wrote:
> I'd like to use bitmapbuttons with a background image. The following
> code works fine, but uncommenting the two lines to show the background
> image causes the button to stop working. Any suggestions appreciated!
> Thanks,
> Kevin
> import wx
> class MyFrame(wx.Frame):
> def __init__(self):
> wx.Frame.__init__(self, None, wx.ID_ANY, 'wxBitmapButton',
> pos=(300, 150), size=(300, 350))
> self.panel1 = wx.Panel(self, -1)
> # bground = wx.Image('Background.png',wx.BITMAP_TYPE_ANY)
> # bgroundbitmap = wx.StaticBitmap(self.panel1, -1,
> wx.BitmapFromImage(bground))
> imageFile = "buttons/bb.png"
> image1 = wx.Image(imageFile,
> wx.BITMAP_TYPE_ANY).ConvertToBitmap()
> self.button1 = wx.BitmapButton(self.panel1, id=-1,
> bitmap=image1,
> pos=(50, 50), size = (image1.GetWidth()+5,
> image1.GetHeight()+5), style = wx.NO_BORDER)
> 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()
> window = MyFrame()
> application.MainLoop()
> --
> To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
> or visithttp://groups.google.com/group/wxPython-users?hl=en
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Bar...@noaa.gov- Hide quoted text -
- Show quoted text -