newbie Q: mouse clicks don't seem to get trapped
Steve Holden
steve at holdenweb.com
Mon Sep 5 12:19:35 EDT 2005
mitsura at skynet.be wrote:
> Hi,
>
> I want to display a window containing an image and when I move the
> mouse over the image and click on the left Mb, I want to get the
> position of the mouse on the image.
> I listed the code to view the image below (so far so good) but for some
> reason the EVT_LEFT_DOWN/UP does not work.
>
> Any idea what might be wrong?
>
> With kind regards,
>
> Kris
>
>
>
> "
> class DisplayPicture(wx.Frame):
> cD = 0
> # bmp = stream that contains the picture (not a filename!)
> # w,h: widht, height of the picture
> def __init__(self, parent, id, title, bmp, w, h):
> wxFrame.__init__(self,parent,wxID_ANY, title, size = ( w, h),
> style=wxDEFAULT_FRAME_STYLE)
>
>
> self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftClick)
> self.Bind(wx.EVT_LEFT_UP, self.OnLeftClick)
>
> Panel=wx.Panel(self)
> wx.StaticBitmap(Panel, -1, bmp, (5, 5) )
>
> self.Show()
>
> def OnLeftClick(self, event):
> print "ok"
> "
>
Without actually running the code (so this may not help), have you
considered binding the events to the panel rather than the frame?
In other words, change
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftClick)
self.Bind(wx.EVT_LEFT_UP, self.OnLeftClick)
Panel=wx.Panel(self)
to
Panel=wx.Panel(self)
Panel.Bind(wx.EVT_LEFT_DOWN, self.OnLeftClick)
Panel.Bind(wx.EVT_LEFT_UP, self.OnLeftClick)
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list
mailing list