本文实例讲述了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程序设计有所帮助。
希望与广大网友互动??
点此进行留言吧!