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

Discussion in 'Python' started by mitsura@skynet.be, Sep 5, 2005.

  1. Guest

    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"
    "
     
    , Sep 5, 2005
    #1
    1. Advertising

  2. Steve Holden Guest

    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/
     
    Steve Holden, Sep 5, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg B
    Replies:
    3
    Views:
    886
  2. Replies:
    3
    Views:
    419
    Claudio Grondi
    Sep 6, 2005
  3. PontiMax

    Clicks and double-clicks

    PontiMax, Jul 14, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    197
    Eliyahu Goldin
    Jul 14, 2004
  4. RichardOnRails

    Undefined local var hash not trapped

    RichardOnRails, Jan 2, 2011, in forum: Ruby
    Replies:
    3
    Views:
    119
    Dhruva Sagar
    Jan 2, 2011
  5. Replies:
    1
    Views:
    440
    Ch Lamprecht
    May 15, 2006
Loading...

Share This Page