wxPython添加菜单

来源:互联网 发布:甬温动车事故 知乎 编辑:程序博客网 时间:2024/05/16 15:34

每个应用程序都应该有一个菜单栏和一个状态栏。让我们将它们添加到我们的:

[python] view plaincopy
  1. self.CreateStatusBar()  
  2.           
  3.         filemenu = wx.Menu()  
  4.         filemenu.Append(wx.ID_ABOUT,"&About","Infomation about this program")  
  5.         filemenu.AppendSeparator()  
  6.         filemenu.Append(wx.ID_EXIT,"E&xit","Close program")  
  7.           
  8.         menuBar = wx.MenuBar()  
  9.         menuBar.Append(filemenu,"&File")  
  10.         self.SetMenuBar(menuBar)  


注意:wx.ID_ABOUT,wx.ID_EXIT都是wxPython的标准组合ID,这是一个好习惯使用标准的ID

完整的程序:

[python] view plaincopy
  1. ''''' 
  2. Created on 2012-6-28 
  3.  
  4. @author: Administrator 
  5. '''  
  6. import wx  
  7.   
  8. class MyFrame(wx.Frame):  
  9.     def __init__(self,parent,title):  
  10.         wx.Frame.__init__(self,parent,title=title,size=(400,300))  
  11.         self.control = wx.TextCtrl(self,style=wx.TE_MULTILINE)  
  12.           
  13.         self.CreateStatusBar()  
  14.           
  15.         filemenu = wx.Menu()  
  16.         filemenu.Append(wx.ID_ABOUT,"&About","Infomation about this program")  
  17.         filemenu.AppendSeparator()  
  18.         filemenu.Append(wx.ID_EXIT,"E&xit","Close program")  
  19.           
  20.         menuBar = wx.MenuBar()  
  21.         menuBar.Append(filemenu,"&File")  
  22.         self.SetMenuBar(menuBar)  
  23.           
  24.         self.Show(True)  
  25.   
  26. app = wx.App(False)  
  27. frame = MyFrame(None,"Small Editor")  
  28. app.MainLoop()  


运行程序应该如下画面:

原创粉丝点击