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的取值主要有以下几种:

wxOKShow an OK button.
wxCANCELShow a Cancel button.
wxYES_NOShow Yes and No buttons.
wxYES_DEFAULTUsed with wxYES_NO, makes Yes button the default - which is the default behaviour.
wxNO_DEFAULTUsed with wxYES_NO, makes No button the default.
wxICON_EXCLAMATIONShows an exclamation mark icon.
wxICON_HANDShows an error icon.
wxICON_ERRORShows an error icon - the same as wxICON_HAND.
wxICON_QUESTIONShows a question mark icon.
wxICON_INFORMATIONShows an information (i) icon.
wxSTAY_ON_TOPThe 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()
        

测试:

转载于:https://www.cnblogs.com/dyx1024/archive/2012/07/07/2580380.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值