您的位置:首页 > 编程语言 > Python开发

Python MenuBar Menu 添加

2016-04-05 09:23 429 查看
<span style="font-family: Arial, Helvetica, sans-serif;">这个例子是关于MenuBar和Menu的建立规则:
1、首先要建立MenuBar对象,然后建立Menu对象
2、将Menu对象添加到MenuBar对象中,用Append方法
3、向Menu对象中添加子菜单项,也是用Append方法
4、将Menu对象中的子菜单项与EVT_MENU事件绑定,用的Bind方法
5、最后,需要将MenuBar对象用<span style="font-family: Arial, Helvetica, sans-serif;">SetMenuBar()显示出来,若没有该处理则菜单项显示不出来的。</span>
</span>
<span style="font-family: Arial, Helvetica, sans-serif;">#!/usr/bin/env python</span>
# -*- coding: utf-8 -*-
import wx

class RefactorExample(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, 'Refactor Example',size=(340, 200))
panel = wx.Panel(self, -1)
panel.SetBackgroundColour('White')

#建立MenuBar
menuBar = wx.MenuBar()

#建立menu1
menu1 = wx.Menu()

#将 menu1 添加到 MenuBar 中
menuBar.Append(menu1,"FILE")

#菜单下划线
menu1.AppendSeparator()

#将details 添加到menu1中
self.menu_details = menu1.Append(wx.ID_ANY,"details")
#将menu_details与ON_OPEN()相关联
self.Bind(wx.EVT_MENU,self.ON_OPEN,self.menu_details)

self.SetMenuBar(menuBar)

def ON_OPEN(self,event):
print "menu_item_on_open"

if __name__ == '__main__':
app = wx.PySimpleApp()
frame = RefactorExample(parent=None)
frame.Show()
app.MainLoop()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python menu