Python wxPython库消息对话框MessageDialog用法示例
作者:socrates 时间:2022-06-15 15:31:57
本文实例讲述了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程序设计有所帮助。
来源:https://blog.csdn.net/dyx1024/article/details/7866717
标签:Python,wxPython,对话框,MessageDialog
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
分享unittest单元测试框架中几种常用的用例加载方法
2023-04-25 06:53:34
![](https://img.aspxhome.com/file/2023/7/105197_0s.png)
Python简单实现阿拉伯数字和罗马数字的互相转换功能示例
2021-08-29 08:52:57
![](https://img.aspxhome.com/file/2023/4/79794_0s.png)
聊聊pytorch中Optimizer与optimizer.step()的用法
2022-03-16 22:45:34
Django框架下在URLconf中指定视图缓存的方法
2023-10-03 01:54:28
Django模板继承与模板的导入实例详解
2023-04-03 14:41:28
![](https://img.aspxhome.com/file/2023/3/92143_0s.gif)
静态页面分页的AJAX实现
2008-01-19 16:19:00
![](https://img.aspxhome.com/file/UploadPic/20081/19/2008119162559319s.jpg)
asp如何计算下载一个文件需要多长时间?
2009-11-25 20:17:00
对Django中内置的User模型实例详解
2022-10-31 05:03:10
使用pytorch进行张量计算、自动求导和神经网络构建功能
2022-08-18 11:50:48
Django Form and ModelForm的区别与使用
2022-04-12 15:28:10
asp如何做一个看他爱不爱你的小测验?
2010-07-11 21:16:00
设计师的底线
2009-05-06 12:51:00
大家都对vertical-align的各说各话
2008-06-19 12:11:00
![](https://img.aspxhome.com/file/UploadPic/20086/19/2008619121517533s.gif)
phpmyadmin报错:#2003 无法登录 MySQL服务器的解决方法
2023-11-19 20:38:45
Oracle常用命令大全集
2010-07-21 13:18:00
页面新开窗口的一点补充
2008-09-10 12:57:00
python 输出所有大小写字母的方法
2021-01-05 01:02:57
pycharm2022没有manage repositories配置镜像源的解决方法
2022-06-27 05:30:24
![](https://img.aspxhome.com/file/2023/9/78449_0s.png)
Bootstrap响应式侧边栏改进版
2023-08-17 02:26:10
![](https://img.aspxhome.com/file/2023/1/56051_0s.jpg)
centos 安装python3.6环境并配置虚拟环境的详细教程
2021-06-10 12:24:49