# wxmouse.py wxPython25 import wx class MyFrame(wx.Frame): """create a color frame, inherits from wx.Frame""" def __init__(self, parent): # -1 is the default ID wx.Frame.__init__(self, parent, -1, "Click for mouse position", size=(400,300), style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE) self.SetBackgroundColour('Goldenrod') self.SetCursor(wx.StockCursor(wx.CURSOR_PENCIL)) # hook some mouse events self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown) def OnLeftDown(self, event): """left mouse button is pressed""" pt = event.GetPosition() # position tuple print pt self.SetTitle('LeftMouse = ' + str(pt)) def OnRightDown(self, event): """right mouse button is pressed""" pt = event.GetPosition() print pt self.SetTitle('RightMouse = ' + str(pt)) app = wx.PySimpleApp() frame = MyFrame(None) frame.Show(True) app.MainLoop()