python菜单栏都是什么意思-Python的菜单栏与对话框的综合运用

1.[文件]

Mess-Example3.py ~ 5KB

下载(58)

#!/usr/bin/python

#-*- encoding: utf-8 -*-

"""

Created on 2014年6月13日

@author: Administrator

"""

import wx

class Example(wx.Frame):

def __init__(self,*args,**kw):

super(Example,self).__init__(*args,**kw)

self.InitUI()

def InitUI(self):

menubar = wx.MenuBar()

help = wx.Menu()

help.Append(100,"&About")

self.Bind(wx.EVT_MENU, self.OnAboutBox, id=100)

menubar.Append(help,"&Help")

help.Append(99,"&Close")

self.Bind(wx.EVT_MENU, self.OnQuit, id=99)

file = wx.Menu()

file.Append(101, "&Open", "Open a new document")

self.Bind(wx.EVT_MENU, self.ShowMessage1, id=101)

file.Append(102, "&Save", "Save the document")

self.Bind(wx.EVT_MENU, self.InitUIx, id=102)

file.AppendSeparator()

menubar.Append(file, "&File")

edit = wx.Menu()

edit.Append(201, "check item1", "", wx.ITEM_CHECK)

edit.Append(202, "check item2", kind= wx.ITEM_CHECK)

menubar.Append(edit, "&Edit")

submenu = wx.Menu()

submenu.Append(301, "radio item1", kind=wx.ITEM_RADIO)

submenu.Append(302, "radio item2", kind=wx.ITEM_RADIO)

submenu.Append(303, "radio item3", kind= wx.ITEM_RADIO)

edit.AppendMenu(203, "submenu", submenu)

self.SetMenuBar(menubar)

panel = wx.Panel(self)

hbox = wx.BoxSizer()

sizer = wx.GridSizer(2,2,2,2)

btn1 = wx.Button(panel,label=u"info提示")

btn2 = wx.Button(panel,label=u"error错误")

btn3 = wx.Button(panel,label=u"question问题确认")

btn4 = wx.Button(panel,label=u"alert警告")

sizer.AddMany([btn1,btn2,btn3,btn4])

hbox.Add(sizer,0,wx.ALL,15)

panel.SetSizer(hbox)

btn1.Bind(wx.EVT_BUTTON, self.ShowMessage1)

btn2.Bind(wx.EVT_BUTTON, self.ShowMessage2)

btn3.Bind(wx.EVT_BUTTON, self.ShowMessage3)

btn4.Bind(wx.EVT_BUTTON, self.ShowMessage4)

self.SetSize((300, 200))

self.SetTitle(u"菜单栏的运用")

self.Centre()

self.Show(True)

def OnQuit(self, e):

print "程序正常关闭"

self.Close()

def ShowMessage1(self,e):

dial = wx.MessageDialog(None,u"你选择了File-Open",u"提示",wx.OK)

dial.ShowModal()

def InitUIx(self,e):

wx.FutureCall(2000,self.ShowMessage)

self.SetSize((300,200))

self.Centre()

self.Show(True)

def ShowMessage(self):

wx.MessageBox(u"2秒钟后,弹出对话框",u"定时对话框",wx.OK|wx.ICON_INFORMATION)

def ShowMessage2(self, event):

dial = wx.MessageDialog(None, "Error loading file", "Error",

wx.OK | wx.ICON_ERROR)

dial.ShowModal()

def ShowMessage3(self, event):

dial = wx.MessageDialog(None, "Are you sure to quit?", "Question",

wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)

dial.ShowModal()

def ShowMessage4(self, event):

dial = wx.MessageDialog(None, "Unallowed operation", "Exclamation",

wx.OK | wx.ICON_EXCLAMATION)

dial.ShowModal()

def OnAboutBox(self,e):

print "OnAboutBox+++"

description = """File Hunter is an advanced file manager for

the Unix operating system. Features include powerful built-in editor,

advanced search capabilities, powerful batch renaming, file comparison,

extensive archive handling and more.

"""

licence = """File Hunter is free software; you can redistribute

it and/or modify it under the terms of the GNU General Public License as

published by the Free Software Foundation; either version 2 of the License,

or (at your option) any later version.

File Hunter is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the GNU General Public License for more details. You should have

received a copy of the GNU General Public License along with File Hunter;

if not, write to the Free Software Foundation, Inc., 59 Temple Place,

Suite 330, Boston, MA 02111-1307 USA"""

info = wx.AboutDialogInfo()

info.SetIcon(wx.Icon("exit.png",wx.BITMAP_TYPE_PNG))

info.SetVersion("2.0")

info.SetDescription(description)

info.SetCopyright("(C) 2007 - 2011 Jan Bodnar")

info.SetWebSite("http://www.zetcode.com")

info.SetLicence(licence)

info.AddDeveloper("Jan Bodnar")

info.AddDocWriter("Jan Bodnar")

info.AddArtist("The Tango crew")

info.AddTranslator("Jan Bodnar")

wx.AboutBox(info)

def main():

ex = wx.App()

Example(None)

ex.MainLoop()

if __name__ == "__main__":

main()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值