标签:alt 按键 ima 创建 bin amp 状态栏 main paste
事件处理是wxPython程序工作的基本机制,先看几个术语:
事件驱动模型:

wx.Event的子类:
wx.EvtHandler的Bind方法:
它用来创建事件绑定,原型如下:
Bind(event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY)
它将一个事件和一个对象与一个事件处理函数绑定。
看一个菜单项选择事件绑定的实例:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
‘‘‘
    Function:常用对话框实例
    Input:NONE
    Output: NONE
    author: socrates
    blog:http://www.cnblogs.com/dyx1024/
    date:2012-07-07
‘‘‘  
import wx
import wx.py.images
class ToolbarFrame(wx.Frame):
    def __init__(self, parent, id):
        
        wx.Frame.__init__(self, parent, id, ‘Toolbars‘, size = (300, 200))
        
        panel = wx.Panel(self)
        panel.SetBackgroundColour(‘White‘)
        
        #创建状态栏
        statusBar = self.CreateStatusBar()
        
        #创建工具栏
        toolbar = self.CreateToolBar()
        #增加一个工具
        toolbar.AddSimpleTool(wx.NewId(), wx.py.images.getPyBitmap(), "New", "Long help for ‘New‘")
        toolbar.AddSimpleTool(wx.NewId(), wx.py.images.getPyBitmap(), "Edit", "Long help for ‘Edit‘")
        #准备显示
        toolbar.Realize()
        
        #创建菜单
        menuBar = wx.MenuBar()
        
        menu1 = wx.Menu()
        menuBar.Append(menu1, "&File") #菜单项目1
        
        menu2 = wx.Menu()
        
        #菜单内容&表示随后的字符为热键,参数3为在状态栏上显示的菜单项说明
        menu_item1 = menu2.Append(wx.NewId(), "&Copy", "Copy in status bar") 
        menu2.Append(wx.NewId(), "C&ut", "")
        menu2.Append(wx.NewId(), "Paste", "")
        menu2.AppendSeparator()
        menu2.Append(wx.NewId(), "&Options...", "Display Options")
        menuBar.Append(menu2, "&Edit")
        self.SetMenuBar(menuBar)
        
        #菜单项事件绑定
        self.Bind(wx.EVT_MENU, self.OnCloseMe, menu_item1)
        
    #消息对话框    
    def OnCloseMe(self, event):
        dlg = wx.MessageDialog(None, u"消息对话框测试", u"标题信息", wx.YES_NO | wx.ICON_QUESTION)
        if dlg.ShowModal() == wx.ID_YES:
            self.Close(True)
        dlg.Destroy()
if __name__ == ‘__main__‘:
    app = wx.PySimpleApp()
    frame = ToolbarFrame(parent = None, id = -1)
    frame.Show()
    app.MainLoop()        
        
测试一下:


标签:alt 按键 ima 创建 bin amp 状态栏 main paste
原文地址:http://www.cnblogs.com/chengxuyuan326260/p/6368745.html