应用 wx.scrollwinevent 事件的一个例子。
该事件是在点击内建的滚动条时产生的。
而通过调用 setscrollbar() 方法,就可以激活内建的滚动条。
对于独立滚动条,对应的事件类型叫做 wx.scrollevent。
专题教程:wxpython中文教程
例子:
 
#!/usr/bin/python
#coding=utf-8
# www.plcxue.com
import wx
class MyScrollWinEvent(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)
        panel = wx.Panel(self, -1)
        self.st = wx.StaticText(panel, -1, '0', (30, 0))
        panel.Bind(wx.EVT_SCROLLWIN, self.OnScroll)
        panel.SetScrollbar(wx.VERTICAL, 0, 6, 50)
        self.Center()
        
    def OnScroll(self, evt):
        y = evt.GetPosition()
        self.st.SetLabel(str(y))
        
class MyApp(wx.App):
    def OnInit(self):
        msw = MyScrollWinEvent(None, -1, 'myscrollwinevent.py')
        msw.Show(True)
        self.SetTopWindow(msw)
        return True
    
app = MyApp(0)
app.MainLoop()
当窗口被缩放时,wx.SizeEvent 就产生了。
本例中,将在标题栏显示窗口的大小。
例子:
 
#!/usr/bin/python
#coding=utf-8
#sizeevent.py
import wx
class SizeEvent(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)
        
        self.Bind(wx.EVT_SIZE, self.OnSize)
        
        self.Center()
    def OnSize(self, event):
        self.SetTitle(str(event.GetSize()))
        
class MyApp(wx.App):
    def OnInit(self):
        se = SizeEvent(None, -1, 'sizeevent.py')
        se.Show(True)
        return True
    
app = MyApp(0)
app.MainLoop()
例3:
 
#!/usr/bin/python
#coding=utf-8
#moveevent.py
import wx
class MoveEvent(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)
        
        wx.StaticText(self, -1, 'x:', (10, 0))
        wx.StaticText(self, -1, 'y:', (10, 20))
        self.st1 = wx.StaticText(self, -1, '', (30, 0))
        self.st2 = wx.StaticText(self, -1, '', (30, 20))
        self.Bind(wx.EVT_MOVE, self.OnMove)
        self.Center()
        
    def OnMove(self, event):
        x, y = event.GetPosition()
        self.st1.SetLabel(str(x))
        self.st2.SetLabel(str(y))
        
class MyApp(wx.App):
    def OnInit(self):
        me = MoveEvent(None, -1, 'moveevent.py')
        me.Show(True)
        return True
    
app = MyApp(0)
app.MainLoop()
 
在窗口被重新绘制 (redrawn)时,绘制 (paint) 事件就产生了。而重绘发生在缩放或最大化窗口时。
程序本身也会导致产生窗口绘制事件。
比如在调用 SetLabel() 方法来改变某个 wx.StaticText部件时。
注意,最小化窗口时,并不会产生绘制事件。
例子:
 
#!/usr/bin/python
#coding=utf-8
#paintevent.py
import wx
class PaintEvent(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)
        
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Center()
        
    def OnPaint(self, event):
        wx.Bell()
        
class MyApp(wx.App):
    def OnInit(self):
        pe = PaintEvent(None, -1, 'paintevent.py')
        pe.Show(True)
        return True
    
app = MyApp(0)
app.MainLoop()
在敲下键盘上的一个按键时,wx.KeyEvent 就产生了. 
按键处理器共有三个:
EVT_KEY_DOWN
EVT_KEY_UP
EVT_CHAR
通常的操作是按下 Esc 键来关闭程序.
例子:
 
#!/usr/bin/python
#coding=utf-8
import wx
class 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.Center()
        self.Show(True)
        
    def OnKeyDown(self, event):
        keycode = event.GetKeyCode()
        if keycode == wx.WXK_ESCAPE:
            ret = wx.MessageBox('你确定要退出吗?', '问题', wx.YES_NO |        wx.CENTER | wx.NO_DEFAULT, self)
            if ret == wx.YES:
                self.Close()
            event.Skip()
            
app = wx.App()
KeyEvent(None, -1, 'keyevent.py')
app.MainLoop()
通过调用 GetKeyCode() 方法,找出按下的按键. 
这里按下的按键代码(keycode) 就是 wx.WXK_ESCAPE.
keycode = event.GetKeyCode()
其它按键代码: