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/we want to unbind a method from an event, we call the Unbind()method. It has the same paremeters as the above one.Vetoing eventsSometimes we need to stop processing an event. To do this, wecall the method Veto().#!/usr/bin/python# veto.pyimport wxclass Veto(wx.Frame):def __init__(self, parent, id, title):wx.Frame.__init__(self, parent, id, title, size=(250, 200))self.Bind(wx.EVT_CLOSE, self.OnClose)self.Centre()self.Show(True)def OnClose(self, event):dial = wx.MessageDialog(None, 'Are you sure to quit?', 'Question',wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)ret = dial.ShowModal()if ret == wx.ID_YES:self.Destroy()else:event.Veto()app = wx.App()Veto(None, -1, 'Veto')app.MainLoop()In our example, we process a wx.CloseEvent. This event iscalled, when we click the X button on the titlebar, press Alt + F4or select close from the system menu. In many applications, wewant to prevent from accidentally closing the window, if wemade some changes. To do this, we must bind thewx.EVT_CLOSE event binder.dial = wx.MessageDialog(None, 'Are you sure to quit?', 'Question',wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)ret = dial.ShowModal()4 de 14 27/04/2008 1:03

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

Saved successfully!

Ooh no, something went wrong!