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

简介:

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/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()




本文转自 lover00751CTO博客,原文链接:http://blog.51cto.com/wangwei007/1209303,如需转载请自行联系原作者
相关文章
|
23天前
Qt实现的多菜单选择界面
Qt实现的多菜单选择界面
23 0
|
2月前
|
索引
MFC工具栏和状态栏
MFC工具栏和状态栏
18 1
electron菜单或托盘点击如何打开新的窗口
electron菜单或托盘点击如何打开新的窗口
electron菜单或托盘点击如何打开新的窗口
CDialog中使用工具栏和状态栏
CDialog中使用工具栏和状态栏
86 0
从零开始学Pyqt5之【控件介绍】(17):菜单栏QMenuBar、QToolBar工具栏、QStatusBar状态栏
从零开始学Pyqt5之【控件介绍】(17):菜单栏QMenuBar、QToolBar工具栏、QStatusBar状态栏
从零开始学Pyqt5之【控件介绍】(17):菜单栏QMenuBar、QToolBar工具栏、QStatusBar状态栏
【QT】QT菜单栏、状态栏、工具栏
【QT】QT菜单栏、状态栏、工具栏
|
Android开发
给Eclipse插件的View加上菜单和工具条
Eclipse的每个视图(View)都有自己的菜单和工具条,View通过与自己相关的IViewSite对象与这些东西打交道,确切的说,是通过这个IViewSite对象的IActionBars对象来管理,ActionBars对象负责菜单、工具条和状态栏。
1475 0