用wx.MessageDialog创建消息对话框
2012-07-15 21:22
288 查看
运行效果图:
Python代码:
wx.MessageDialog函数参数如下:
wx.MessageDialog(parent, message, caption, style
= wxOK | wxCANCEL, pos = wxDefaultPosition)
style的取值主要有以下几种:
在看看相关的wx.ShowModal()函数,它使用应用程序在对话框关闭前不能响应其它窗口的用户事件,返回一个整数,取值如下:
wx.ID_YES, wx.ID_NO, wx.ID_CANCEL, wx.ID_OK。
例子二:
效果图:
例子三:
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Hello My Message", size=(300,200))
panel=wx.Panel(self)
b = wx.Button(panel, -1, "Show a Message", (100,50))
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
self.Bind(wx.EVT_CLOSE, self.OnClose)
self.Show()
def OnButton(self, evt):
dlg = wx.MessageDialog(self, 'Hello from Python and wxPython!',
'A Message Box',
wx.OK | wx.ICON_INFORMATION
#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
)
dlg.ShowModal()
dlg.Destroy()
evt.Skip()
def OnClose(self, evt):
dlg = wx.MessageDialog(self, 'Are you sure you want to close My Frame?',
'Close Frame', wx.YES_NO | wx.ICON_QUESTION)
ret = dlg.ShowModal()
dlg.Destroy()
if ret == wx.ID_YES:
evt.Skip()
app = wx.App(0)
MyFrame()
app.MainLoop()
效果图:
Python代码:
#!/usr/bin/env python # -*- encoding:utf-8 -*- 'Create MessageDialog Example' import wx class MyFrame(wx.Frame): def __init__(self,parent,id): wx.Frame.__init__(self,parent,id,'MessageDialog',size=(300,200)) panel=wx.Panel(self) box=wx.MessageDialog(None,'Go On?','Message',wx.OK) answer=box.ShowModal() box.Destroy() if __name__=='__main__': app=wx.PySimpleApp() myframe=MyFrame(parent=None,id=-1) myframe.Show(True) app.MainLoop()
wx.MessageDialog函数参数如下:
wx.MessageDialog(parent, message, caption, style
= wxOK | wxCANCEL, pos = wxDefaultPosition)
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). |
wx.ID_YES, wx.ID_NO, wx.ID_CANCEL, wx.ID_OK。
例子二:
#!/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()
效果图:
例子三:
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Hello My Message", size=(300,200))
panel=wx.Panel(self)
b = wx.Button(panel, -1, "Show a Message", (100,50))
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
self.Bind(wx.EVT_CLOSE, self.OnClose)
self.Show()
def OnButton(self, evt):
dlg = wx.MessageDialog(self, 'Hello from Python and wxPython!',
'A Message Box',
wx.OK | wx.ICON_INFORMATION
#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
)
dlg.ShowModal()
dlg.Destroy()
evt.Skip()
def OnClose(self, evt):
dlg = wx.MessageDialog(self, 'Are you sure you want to close My Frame?',
'Close Frame', wx.YES_NO | wx.ICON_QUESTION)
ret = dlg.ShowModal()
dlg.Destroy()
if ret == wx.ID_YES:
evt.Skip()
app = wx.App(0)
MyFrame()
app.MainLoop()
效果图:
相关文章推荐
- Java中 子线程JOptionPane.showMessageDialog()创建对话框不能正常显示,显示空白,也不能接受消息的问题
- MFC小程序003------MFC使用WebBrowser组件,在对话框中创建滚动视图,动态创建一个静态文本控件并设置鼠标单击的消息响应
- <MFC>消息对话框的创建弹出
- <MFC>消息对话框的创建弹出
- MFC动态创建对话框中的按钮控件并创建其响应消息
- MFC中,我从一个对话框,同时在按钮的消息处理函数中利用DoModal()函数一级一级的创建许多模态对话框,那么怎样从某个子对话框返回第一个对话框呢?
- MFC小程序003------MFC使用WebBrowser组件,在对话框中创建滚动视图,动态创建一个静态文本控件并设置鼠标单击的消息响应
- windows 窗口创建,消息泵,对话框,控件常用API
- MFC应用程序中处理消息,创建窗口的过程,关闭窗口(非模态窗口),打开模式对话框等的函数调用顺序 .
- MFC应用程序中处理消息,创建窗口的过程,关闭窗口(非模态窗口),打开模式对话框等的函数调用顺序
- 创建消息对话框的两种方式
- 使用AlertDialog创建简单的对话框1-显示提示消息的对话框
- 【Android开发】消息提示框与对话框-使用AlertDialog创建对话框
- Android 官方推荐 : DialogFragment 创建对话框
- [置顶] 如何在你的控制台程序里创建消息循环
- 关于STO 创建时ME 083 错误消息调试
- 去掉在模态对话框处理鼠标跟键盘消息时,出现系统提示声音
- QT之创建登录对话框
- MFC应用程序中处理消息的顺序,创建窗口的过程关闭窗口的顺序(非模态窗口),打开模式对话框的函数调用顺序
- firefox 阻止此页面创建其他对话框的解决方法