wxpython 给框架增加菜单栏,工具栏和状态栏

# _*_ coding: utf-8 _*_
__author__ = 'pythonwu'
__date__ = "2018/5/15 16:20"

import wx
from wx.py.shell import ShellFrame
from wx.py.filling import FillingFrame
import wx.py.images as 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(),images.getPyBitmap(),"New","Long help for 'New'") #给工具栏增加一个工具
toolBar.Realize() #准备显示工具栏
menuBar = wx.MenuBar() #创建菜单栏
#创建两个菜单
menu1 = wx.Menu()
menuBar.Append(menu1,"&File")
menu2 = wx.Menu()
#创建菜单的项目
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") #在菜单栏上附上菜单
#创建debug菜单及其菜单项
menu3 = wx.Menu()
shell = menu3.Append(-1,"&wxPython sehll","Open wxPython shell frame")
filling = menu3.Append(-1,"&Namespace viewer","OPen namespace viewer frame")
menuBar.Append(menu3,"&Debug")
#设置菜单的事件处理器
self.Bind(wx.EVT_MENU,self.OnShell,shell)
self.Bind(wx.EVT_MENU,self.OnFilling,filling)
self.SetMenuBar(menuBar)
#消息对话框
# dlg = wx.MessageDialog(panel,"Is this the coolest thing ever!","MessageDialog",wx.YES_NO|wx.ICON_QUESTION)
# result = dlg.ShowModal()
# dlg.Destroy()
#文本输入对话框
# dlg = wx.TextEntryDialog(panel,"Is this the coolest thing ever!","MessageDialog",'Gary')
# if dlg.ShowModal()== wx.ID_OK:
# response = dlg.GetValue()
#从一个列表中选择
# dlg = wx.SingleChoiceDialog(panel,"Is this the coolest thing ever!","MessageDialog",['1','2','3'])
# if dlg.ShowModal()== wx.ID_OK:
# response = dlg.GetStringSelection()
def OnCloseMe(self,e):
self.Close(True)
def OnCloseWindow(self,e):
self.Destroy()
# OnShell菜单项和OnFilling菜单项处理器
def OnShell(self,e):
frame = ShellFrame(parent=self)
frame.Show()
def OnFilling(self,e):
frame = FillingFrame(parent=self)
frame.Show()

if __name__ == '__main__':
app = wx.PySimpleApp()
frame = ToolBarFrame(parent=None,id= -1)
frame.Show()
app.MainLoop()

"""
ShowModal()方法将对话框以模式框架的方式显示,这意味着在对话框关
闭之前,应用程序中的别的窗口不能响应用户事件。ShowModal()方法的返回
值是一个整数,对于wx.MessageDialog,返回值是下面常量之
一: wx.ID_YES, wx.ID_NO, wx.ID_CANCEL, wx.ID_OK。
"""
posted @ 2018-05-17 15:52  五等码农  阅读(1689)  评论(0编辑  收藏  举报