'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
Solution 1:[1]
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
...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Martin Finke |
