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/app = wx.App()PaintEvent(None, -1, 'paintevent.py')app.MainLoop()In our example we print the number of paint events generatedinto the console.KeyEventWhen we press a key on our keyboard, wx.KeyEvent isgenerated. This event is sent to the widget that has currentlyfocus. <strong>The</strong>re are three different key handlers:wx.EVT_KEY_DOWNwx.EVT_KEY_UPwx.EVT_CHARA common request is to close application, when Esc key ispressed.#!/usr/bin/python# keyevent.pyimport wxclass KeyEvent(wx.Frame):def __init__(self, parent, id, title):wx.Frame.__init__(self, parent, id, title)panel = wx.Panel(self, -1)panel.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)panel.SetFocus()self.Centre()self.Show(True)def OnKeyDown(self, event):keycode = event.GetKeyCode()if keycode == wx.WXK_ESCAPE:ret = wx.MessageBox('Are you sure to quit?', 'Question',wx.YES_NO | wx.NO_DEFAULT, self)if ret == wx.YES:self.Close()event.Skip()app = wx.App()KeyEvent(None, -1, 'keyevent.py')app.MainLoop()13 de 14 27/04/2008 1:03

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

Saved successfully!

Ooh no, something went wrong!