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

本文实例讲述了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()

测试:

20189393631254.png?2018839375

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

希望与广大网友互动??

点此进行留言吧!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值