代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Python
】
Python的菜单栏与对话框的综合运用
作者:
Java的生涯
/ 发布于
2014/6/17
/
404
写程序时,经常用到对话框,而且,好一点的项目,还会用到菜单栏,以下是Python的菜单栏与对话框的综合运用:
#!/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()
试试其它关键字
菜单栏
对话框
同语言下
.
比较两个图片的相似度
.
过urllib2获取带有中文参数的url内容
.
不下载获取远程图片的宽度和高度及文件大小
.
通过qrcode库生成二维码
.
通过httplib发送GET和POST请求
.
Django下解决小文件下载
.
遍历windows的所有窗口并输出窗口标题
.
根据窗口标题调用窗口
.
python 抓取搜狗指定公众号
.
pandas读取指定列
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Java的生涯
贡献的其它代码
(
1
)
.
Python的菜单栏与对话框的综合运用
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3