wxPython添加菜单

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

[python] view plain copy
  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 plain copy
  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()  


运行程序应该如下画面:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值