简体   繁体   中英

How can I detect an "unClick" in wxPython?

I want to detect the difference of position between when I left-click in a panel and when I finish clicking (when the left button goes up after the click). I detect correctly the click and I know how to get the position of the mouse but I don't know how to detect when the click ends This is how I associate the event of the left-click to the panel:

    x = wx.Panel(self, wx.ID_ANY)
    x.SetBackgroundColour(wx.Colour(self.colores[aux2[1]]))
    x.SetMinSize((20,20))
    x.Bind(wx.EVT_LEFT_DOWN, self.onClick)

This is the event handler:

def onClick(self, event):
        if (self.modo == 'jugando'):
            print('click')

And this is the output of the program:

click

So I know that I enter correctly in the handler but I don't know how can I detect when the left button of the mouse goes up afther this

I would do it this way:

x = wx.Panel(self, wx.ID_ANY)
x.SetBackgroundColour(wx.Colour(self.colores[aux2[1]]))
x.SetMinSize((20,20))
x.Bind((wx.EVT_MOUSE_EVENTS, self.onMouseEvent)

Event handling:

def onMouseEvent(self, event):
    if event.LeftDown():
        self.previous_position = event.Position
    elif event.LeftUp():
        self.current_position = event.Position
        ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM