13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Events in <strong>wxPython</strong>http://www.zetcode.com/wxpython/events/During the close event, we show a message dialog.if ret == wx.ID_YES:self.Destroy()else:event.Veto()Depending on the return value, we destroy the window, or vetothe event. Notice that to close the window, we must call theDestroy() method. By calling the Close() method, we would endup in an endless cycle.Event propagation<strong>The</strong>re are two types of events. Basic events and commandevents. <strong>The</strong>y differ in propagation. Event propagation istravelling of events from child widgets to parent widgets andgrand parent widgets etc. Basic events do not propagate.Command events do propagate. For example wx.CloseEvent is abasic event. It does not make sense for this event to propagateto parent widgets.By default, the event that is catched in a event handler stopspropagating. To continue propagation, we must call the Skip()method.#!/usr/bin/python# propagate.pyimport wxclass MyPanel(wx.Panel):def __init__(self, parent, id):wx.Panel.__init__(self, parent, id)self.Bind(wx.EVT_BUTTON, self.OnClicked)def OnClicked(self, event):print 'event reached panel class'event.Skip()class MyButton(wx.Button):def __init__(self, parent, id, label, pos):wx.Button.__init__(self, parent, id, label, pos)5 de 14 27/04/2008 1:03

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

Saved successfully!

Ooh no, something went wrong!