13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Events in <strong>wxPython</strong>http://www.zetcode.com/wxpython/events/import wxclass MoveEvent(wx.Frame):def __init__(self, parent, id, title):wx.Frame.__init__(self, parent, id, title, size=(250, 180))wx.StaticText(self, -1, 'x:', (10,10))wx.StaticText(self, -1, 'y:', (10,30))self.st1 = wx.StaticText(self, -1, '', (30, 10))self.st2 = wx.StaticText(self, -1, '', (30, 30))self.Bind(wx.EVT_MOVE, self.OnMove)self.Centre()self.Show(True)def OnMove(self, event):x, y = event.GetPosition()self.st1.SetLabel(str(x))self.st2.SetLabel(str(y))app = wx.App()MoveEvent(None, -1, 'move event')app.MainLoop()<strong>The</strong> example displays the current position of the window.self.Bind(wx.EVT_MOVE, self.OnMove)Here we bind the wx.EVT_MOVE event binder to the OnMove()method.def OnMove(self, event):x, y = event.GetPosition()<strong>The</strong> event parameter in the OnMove() method is an objectspecific to a particular event type. In our case it is the instanceof a wx.MoveEvent class. This object holds information about theevent. For example the Event object or the position of thewindow. In our case the Event object is the wx.Frame widget.We can find out the current position by calling the GetPosition()method of the event.2 de 14 27/04/2008 1:03

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!