Member Avatar

How can I capture a mouse click on a wx.Panel so that a circle is drawn wherever the mouse is clicked on the panel?

Generally ...

# get the position of the mouse when clicked or moved
# vega

import wx

class MyFrame(wx.Frame):
    """create a color frame, inherits from wx.Frame"""
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, wx.ID_ANY, "Move or click mouse")
        # give it a fancier cursor

        # bind some mouse events
        self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
        self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
        self.Bind(wx.EVT_MOTION, self.OnMotion)

    def OnLeftDown(self, event):
        """left mouse button is pressed"""
        pt = event.GetPosition()  # position tuple
        self.SetTitle('LeftMouse click at = ' + str(pt))

    def OnRightDown(self, event):
        """right mouse button is pressed"""
        pt = event.GetPosition()
        self.SetTitle('RightMouse click at = ' + str(pt))

    def OnMotion(self, event):
        """mouse in motion"""
        pt = event.GetPosition()
        self.SetTitle('Mouse in motion at = ' + str(pt))

app = wx.App(0)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.