您的位置:首页 > 编程语言 > Python开发

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

2013-05-24 17:23 302 查看
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.EVT_MENU,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()


本文出自 “王伟” 博客,请务必保留此出处http://wangwei007.blog.51cto.com/68019/1209303
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: