newbie Q: mouse clicks don't seem to get trapped

M

mitsura

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"
"
 
S

Steve Holden

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top