wxPython中工具栏、状态栏、菜单实现

    wxPython是python可视化编程中的一个很好的模块,以下的代码主要讲述工具栏、状态栏、菜单、菜单事件的实现(可参考:http://www.czug.org/python/wxpythoninaction/):


    #!/usr/bin/env python
    # -- coding: utf-8 --
    import wx
    import wx.py.images
    class ToolbarFrame(wx.Frame):
    def init(self, parent, id):

    wx.Frame.init(self, parent, id, 'Toolbars', size = (600, 400))

    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, u"&文件") #菜单项目1
    self.close = menu1.Append(wx.NewId(), u"退出(&X)", "")
    menu2 = wx.Menu()
    #菜单内容&表示随后的字符为热键,参数3为在状态栏上显示的菜单项说明
    self.Copy = menu2.Append(wx.NewId(), "&Copy", "Copy in status bar")
    self.Cut = menu2.Append(wx.NewId(), "C&ut", "")
    self.Paste = menu2.Append(wx.NewId(), "Paste", "")
    menu2.AppendSeparator()
    self.Options = menu2.Append(wx.NewId(), "&Options…", "Display Options")
    self.Edit = menuBar.Append(menu2, "&Edit")
    self.SetMenuBar(menuBar)
    #调用菜单下拉的退出事件
    self.Bind(wx.EVTMENU,self.OnClose,self.close)
    def OnClose(self,event):#退出事件
    self.Close()
    if name == '_main
    ':
    app = wx.PySimpleApp()
    frame = ToolbarFrame(parent = None, id = -1)
    frame.Show()
    app.MainLoop()