[wxPython-users] button event on bitmap newbie question

Robin Dunn robin at alldunn.com
Mon Apr 2 11:29:33 PDT 2007


gabriel wrote:
> I am new to wxPython, and like very much what I've seen so far (having
> used tkinter and pygtk before). However, now I am stuck with a problem
> and hope someone can help out.
> 
> I want to draw a lot of bitmaps on a window. This works well (following
> the Cookbook example of DoubleBufferedDrawing,
> http://wiki.wxpython.org/index.cgi/DoubleBufferedDrawing pretty much
> exactly). 
> 
> My question is how can I bind Button events to individual bitmaps?
> Apparently one cannot bind directly to wx.Bitmap objects. I think it is
> possible with wx.StaticBitmap objects, but the approach of the Cookbook
> example works much better for me (it draws fast!).

You can either keep track of the location of all your bitmaps, and then 
write a HitTest function that is able to translate mouse events on your 
canvas to the bitmap that they occurred on, and then send an event with 
the info you need.  Or you can use something like OGL or FloatCanvas 
that already does this for you.


-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





More information about the wxpython-users mailing list