Python wxPython库消息对话框MessageDialog用法示例


Posted in Python onSeptember 03, 2018

本文实例讲述了Python wxPython库消息对话框MessageDialog用法。分享给大家供大家参考,具体如下:

消息对话框即我们平时说的Messagebox,看看它的原型,下面是wxWidgets中的原型定义,C++风格,与python风格的区别就是wx前缀与后面名称直接相连,例如wxMessageDialog,在wxpython中使用时就是wx.MessageDialog

wxMessageDialog(wxWindow* parent, const wxString& message, const wxString& caption = "Message box", long style = wxOK | wxCANCEL, const wxPoint& pos = wxDefaultPosition)

其各参数不多做介绍,主要看看ShowModal()方法,它使用应用程序在对话框关闭前不能响应其它窗口的用户事件,返回一个整数,取值如下:

wx.ID_YES, wx.ID_NO, wx.ID_CANCEL, wx.ID_OK

另外,style的取值主要有以下几种:

wxOK Show an OK button.
wxCANCEL Show a Cancel button.
wxYES_NO Show Yes and No buttons.
wxYES_DEFAULT Used with wxYES_NO, makes Yes button the default - which is the default behaviour.
wxNO_DEFAULT Used with wxYES_NO, makes No button the default.
wxICON_EXCLAMATION Shows an exclamation mark icon.
wxICON_HAND Shows an error icon.
wxICON_ERROR Shows an error icon - the same as wxICON_HAND.
wxICON_QUESTION Shows a question mark icon.
wxICON_INFORMATION Shows an information (i) icon.
wxSTAY_ON_TOP The message box stays on top of all other window, even those of the other applications (Windows only).

还是看一个例子:

代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import wx
class MyFrame(wx.Frame):
 def __init__(self, parent, id):
  wx.Frame.__init__(self, parent, id, u'测试面板Panel', size = (600, 300))
  #创建面板
  panel = wx.Panel(self)
  #在Panel上添加Button
  button = wx.Button(panel, label = u'关闭', pos = (150, 60), size = (100, 60))
  #绑定单击事件
  self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
 def OnCloseMe(self, event):
  dlg = wx.MessageDialog(None, u"消息对话框测试", u"标题信息", wx.YES_NO | wx.ICON_QUESTION)
  if dlg.ShowModal() == wx.ID_YES:
   self.Close(True)
  dlg.Destroy()
if __name__ == '__main__':
 app = wx.PySimpleApp()
 frame = MyFrame(parent = None, id = -1)
 frame.Show()
 app.MainLoop()

测试:

Python wxPython库消息对话框MessageDialog用法示例

希望本文所述对大家Python程序设计有所帮助。

Python 相关文章推荐
python实现简单socket通信的方法
Apr 19 Python
Python中二维列表如何获取子区域元素的组成
Jan 19 Python
python的文件操作方法汇总
Nov 10 Python
Python cookbook(数据结构与算法)从字典中提取子集的方法示例
Mar 22 Python
深入了解Python在HDA中的应用
Sep 05 Python
Python + Flask 实现简单的验证码系统
Oct 01 Python
Django Xadmin多对多字段过滤实例
Apr 07 Python
matplotlib 生成的图像中无法显示中文字符的解决方法
Jun 10 Python
python实现数据结构中双向循环链表操作的示例
Oct 09 Python
Python的scikit-image模块实例讲解
Dec 30 Python
pandas提升计算效率的一些方法汇总
May 30 Python
Python 类,对象,数据分类,函数参数传递详解
Sep 25 Python
Python中关键字global和nonlocal的区别详解
Sep 03 #Python
python leetcode 字符串相乘实例详解
Sep 03 #Python
Python模拟自动存取款机的查询、存取款、修改密码等操作
Sep 02 #Python
Python实现多级目录压缩与解压文件的方法
Sep 01 #Python
Python实现压缩文件夹与解压缩zip文件的方法
Sep 01 #Python
Python pymongo模块常用操作分析
Sep 01 #Python
Python实现提取XML内容并保存到Excel中的方法
Sep 01 #Python
You might like
DC《神奇女侠2》因疫情推迟上映 温子仁新恐怖片《恶性》撤档
2020/04/09 欧美动漫
Home Coffee Roasting
2021/03/03 咖啡文化
php处理restful请求的路由类分享
2014/02/27 PHP
php基于ob_start(ob_gzhandler)实现网页压缩功能的方法
2017/02/18 PHP
PHP清除缓存的几种方法总结
2017/09/12 PHP
在Laravel中使用GuzzleHttp调用第三方服务的API接口代码
2019/10/15 PHP
php post换行的方法
2020/02/03 PHP
HTML颜色选择器实现代码
2010/11/23 Javascript
jsonp原理及使用
2013/10/28 Javascript
JavaScript、tab切换完整版(自动切换、鼠标移入停止、移开运行)
2016/01/05 Javascript
JS使用正则表达式实现关键字替换加粗功能示例
2016/08/03 Javascript
很酷的星级评分系统原生JS实现
2016/08/25 Javascript
Bootstrap table的使用方法
2016/11/02 Javascript
利用Node.js编写跨平台的spawn语句详解
2017/02/12 Javascript
微信小程序 五星评分的实现实例
2017/08/04 Javascript
vue+springboot实现项目的CORS跨域请求
2018/09/05 Javascript
更改Python命令行交互提示符的方法
2015/01/14 Python
python分析apache访问日志脚本分享
2015/02/26 Python
Python获取DLL和EXE文件版本号的方法
2015/03/10 Python
Python基于matplotlib绘制栈式直方图的方法示例
2017/08/09 Python
Python第三方Window模块文件的几种安装方法
2018/11/22 Python
python3对接mysql数据库实例详解
2019/04/30 Python
PyQt5 实现给窗口设置背景图片的方法
2019/06/13 Python
Python pandas库中的isnull()详解
2019/12/26 Python
Python2和Python3中@abstractmethod使用方法
2020/02/04 Python
python爬虫scrapy基于CrawlSpider类的全站数据爬取示例解析
2021/02/20 Python
HTML5输入框下拉菜单功能的示例代码
2020/09/08 HTML / CSS
萌新的HTML5 入门指南
2020/11/06 HTML / CSS
台湾网友喜爱的综合型网路购物商城:Yahoo! 奇摩购物中心
2018/03/10 全球购物
意大利宠物用品购物网站:Bauzaar
2018/09/15 全球购物
波兰多品牌运动商店:StreetStyle24.pl
2020/09/22 全球购物
如果让你测试一台高速激光打印机,你都会进行哪些测试
2012/12/04 面试题
致标枪运动员广播稿
2014/02/06 职场文书
我的中国梦口号
2014/06/16 职场文书
勤俭节约倡议书范文
2015/04/29 职场文书
Vue+TypeScript中处理computed方式
2022/04/02 Vue.js