Python wxPython庫消息對話框MessageDialog用法示例
本文實例講述了Python wxPython庫消息對話框MessageDialog用法。分享給大家供大家參考,具體如下:
消息對話框即我們平時說的Messagebox,看看它的原型,下面是wxWidgets中的原型定義,C++風(fēng)格,與python風(fēng)格的區(qū)別就是wx前綴與后面名稱直接相連,例如wxMessageDialog,在wxpython中使用時就是wx.MessageDialog
wxMessageDialog(wxWindow* parent, const wxString& message, const wxString& caption = "Message box", long style = wxOK | wxCANCEL, const wxPoint& pos = wxDefaultPosition)
其各參數(shù)不多做介紹,主要看看ShowModal()方法,它使用應(yīng)用程序在對話框關(guān)閉前不能響應(yīng)其它窗口的用戶事件,返回一個整數(shù),取值如下:
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)) #創(chuàng)建面板 panel = wx.Panel(self) #在Panel上添加Button button = wx.Button(panel, label = u'關(guān)閉', 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()
測試:

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python Socket編程技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設(shè)計有所幫助。
- python文件選擇對話框的操作方法
- Python 使用PyQt5 完成選擇文件或目錄的對話框方法
- Python PyQt5標準對話框用法示例
- python3+PyQt5+Qt Designer實現(xiàn)擴展對話框
- python GUI庫圖形界面開發(fā)之PyQt5打開保存對話框QFileDialog詳細使用方法與實例
- python的tkinter布局之簡單的聊天窗口實現(xiàn)方法
- 教你用Python創(chuàng)建微信聊天機器人
- python操作微信自動發(fā)消息的實現(xiàn)(微信聊天機器人)
- 基于Python如何使用AIML搭建聊天機器人
- python實現(xiàn)簡易聊天對話框
相關(guān)文章
Python表格數(shù)據(jù)處理庫之tablib庫詳解
這篇文章主要介紹了Python表格數(shù)據(jù)處理庫之tablib庫詳解,Tablib是一個用于處理電子表格數(shù)據(jù)的Python庫,它可以輕松地進行數(shù)據(jù)的導(dǎo)入和導(dǎo)出,以及數(shù)據(jù)格式的轉(zhuǎn)換,需要的朋友可以參考下2023-08-08
Python實戰(zhàn)之夢幻鋼琴小游戲的實現(xiàn)
這篇文章主要為大家詳細介紹了如何利用Python語言編寫一款界面化的(Tkinter)電子鋼琴小程序,文中的示例代碼講解詳細,感興趣的可以了解一下2023-02-02
Python實現(xiàn)字典按照value進行排序的方法分析
這篇文章主要介紹了Python實現(xiàn)字典按照value進行排序的方法,結(jié)合實例形式分析了Python字典按照value進行排序的相關(guān)操作技巧,需要的朋友可以參考下2017-12-12

