Python mouse EVT_COMMAND_LEFT_CLICK, EVT_LEFT_DOWN

kyosohma at gmail.com kyosohma at gmail.com
Thu Dec 27 12:09:51 EST 2007


On Dec 27, 10:59 am, SMALLp <po... at mzm.hr> wrote:
> Hy!
> I'm not able to tu bind mouse click event. Code:
>
> class MouseClass(wx.Panel):
>         def __init__(self, parent, id):
>
>                 wx.Panel.__init__(self, parent, id, size=(500, 300))
>                 self.SetBackgroundColour("WHITE")
>
>                 sizer = wx.BoxSizer(wx.VERTICAL)
>
>                 testPanel.SetBackgroundColour("BLACK")
>                 self.Bind(wx.EVT_COMMAND_LEFT_CLICK, self.open, id=testPanel.GetId())
>                 sizer.Add(testPanel, 0, wx.EXPAND)
>                 self.SetSizerAndFir(sizer)
>
>         def open(self, event):
>                 print "yea"
>
> U  tried EVT_LEFT_DOWN as I found on goofle and couldnt get it to work.
> Please help.


It would help if you included working code, for one thing. Maybe I'm
blind, but I don't see a sub-panel getting instantiated with the name
"testPanel".

SetSizerAndFir is not a valid wx command.

All you need can be found here: http://www.wxpython.org/docs/api/wx.MouseEvent-class.html

If you do the following, it works:

<code>

import wx

class MouseClass(wx.Panel):
    def __init__(self, parent, id):

            wx.Panel.__init__(self, parent, id, size=(500, 300))
            self.SetBackgroundColour("WHITE")

            self.Bind(wx.EVT_LEFT_DOWN, self.open, id=self.GetId())


    def open(self, event):
            print "yea"

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frm = wx.Frame(None, wx.ID_ANY, 'Mouse-click test')
    panel = MouseClass(frm, wx.ID_ANY)
    frm.Show()
    app.MainLoop()

</code>

One other note: wxPython issues should be reported to the wxPython
user's group.

HTH

Mike



More information about the Python-list mailing list