Python - Mouse Capture


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. import wx
  2.  
  3. class MyFrame(wx.Frame):
  4.  
  5. def __init__(self):
  6.  
  7. # creo un frame
  8. wx.Frame.__init__(self, None, -1, 'My Frame', size=(300, 300))
  9. # aggiungo un pannello
  10. panel = wx.Panel(self, -1)
  11. # aggiungo un evento al pannello
  12. panel.Bind(wx.EVT_MOTION, self.OnMove)
  13. # aggiungo un controllo di testo
  14. self.posCtrl = wx.TextCtrl(panel, -1, 'Pos: ', pos=(40, 10))
  15.  
  16. def OnMove(self, event):
  17.  
  18. # catturo la posizione del mouse
  19. pos = event.GetPosition()
  20. # scrivo tale posizione nel controllo di testo
  21. self.posCtrl.SetValue('%s, %s' % (pos.x, pos.y))
  22.  
  23. if '__main__' == __name__:
  24.  
  25. app = wx.PySimpleApp()
  26. frame = MyFrame()
  27. frame.Show()
  28. app.MainLoop()

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.