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/Figure: standard identifiers<strong>The</strong> last option is to use own identifiers. We define our ownglobal ids.Miscellaneous eventsFocus event<strong>The</strong> focus indicates the currently selected widget in application.<strong>The</strong> text entered from the keyboard or pasted from the clipboardis sent to the widget, which has the focus. <strong>The</strong>re are two eventtypes concering focus. <strong>The</strong> wx.EVT_SET_FOCUS event, whichis generated when a widget receives focus. <strong>The</strong>wx.EVT_KILL_FOCUS is generated, when the widget loosesfocus. <strong>The</strong> focus is changed by clicking or by a keybord key.Usually Tab/Shift+Tab.#!/usr/bin/python# focusevent.pyimport wxclass MyWindow(wx.Panel):def __init__(self, parent):wx.Panel.__init__(self, parent, -1)self.color = '#b3b3b3'self.Bind(wx.EVT_PAINT, self.OnPaint)self.Bind(wx.EVT_SIZE, self.OnSize)self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)def OnPaint(self, event):dc = wx.PaintDC(self)dc.SetPen(wx.Pen(self.color))x, y = self.GetSize()dc.DrawRectangle(0, 0, x, y)def OnSize(self, event):self.Refresh()def OnSetFocus(self, event):self.color = '#0099f7'self.Refresh()9 de 14 27/04/2008 1:03

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

Saved successfully!

Ooh no, something went wrong!