每个应用程序都应该有一个菜单栏和一个状态栏。让我们将它们添加到我们的:
self.CreateStatusBar()
filemenu = wx.Menu()
filemenu.Append(wx.ID_ABOUT,"&About","Infomation about this program")
filemenu.AppendSeparator()
filemenu.Append(wx.ID_EXIT,"E&xit","Close program")
menuBar = wx.MenuBar()
menuBar.Append(filemenu,"&File")
self.SetMenuBar(menuBar)
注意:wx.ID_ABOUT,wx.ID_EXIT都是wxPython的标准组合ID,这是一个好习惯使用标准的ID
完整的程序:
'''
Created on 2012-6-28
@author: Administrator
'''
import wx
class MyFrame(wx.Frame):
def __init__(self,parent,title):
wx.Frame.__init__(self,parent,title=title,size=(400,300))
self.control = wx.TextCtrl(self,style=wx.TE_MULTILINE)
self.CreateStatusBar()
filemenu = wx.Menu()
filemenu.Append(wx.ID_ABOUT,"&About","Infomation about this program")
filemenu.AppendSeparator()
filemenu.Append(wx.ID_EXIT,"E&xit","Close program")
menuBar = wx.MenuBar()
menuBar.Append(filemenu,"&File")
self.SetMenuBar(menuBar)
self.Show(True)
app = wx.App(False)
frame = MyFrame(None,"Small Editor")
app.MainLoop()
运行程序应该如下画面: