大多数现代的GUI应用程序,对话框窗口或对话框是不可或缺的一部分。一个对话框被定义为两个或以上的人之间的谈话。在一个计算机应用一个对话框窗口用于“交谈”应用程序。一个对话框用于输入数据、修改数据的修改应用程序的设置等。对话框是重要的通信手段之间的一个用户和计算机程序。
#!/usr/bin/python
#-*- encoding: utf-8 -*-
'''
Created on 2014年6月13日
@author: Administrator
'''
import wx
class Example(wx.Frame):
def __init__(self,*args,**kw):
super(Example,self).__init__(*args,**kw)
self.InitUI()
def InitUI(self):
panel = wx.Panel(self)
hbox = wx.BoxSizer()
sizer = wx.GridSizer(2,2,2,2)
btn1 = wx.Button(panel,label='info')
btn2 = wx.Button(panel,label='error')
btn3 = wx.Button(panel,label='question')
btn4 = wx.Button(panel,label='alert')
sizer.AddMany([btn1,btn2,btn3,btn4])
hbox.Add(sizer,0,wx.ALL,15)
panel.SetSizer(hbox)
btn1.Bind(wx.EVT_BUTTON, self.ShowMessage1)
btn2.Bind(wx.EVT_BUTTON, self.ShowMessage2)
btn3.Bind(wx.EVT_BUTTON, self.ShowMessage3)
btn4.Bind(wx.EVT_BUTTON, self.ShowMessage4)
self.SetSize((300, 200))
self.SetTitle('Messages')
self.Centre()
self.Show(True)
def ShowMessage1(self,e):
dial = wx.MessageDialog(None,'Download completed','info',wx.OK)
dial.ShowModal()
def ShowMessage2(self, event):
dial = wx.MessageDialog(None, 'Error loading file', 'Error',
wx.OK | wx.ICON_ERROR)
dial.ShowModal()
def ShowMessage3(self, event):
dial = wx.MessageDialog(None, 'Are you sure to quit?', 'Question',
wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
dial.ShowModal()
def ShowMessage4(self, event):
dial = wx.MessageDialog(None, 'Unallowed operation', 'Exclamation',
wx.OK | wx.ICON_EXCLAMATION)
dial.ShowModal()
def main():
ex = wx.App()
Example(None)
ex.MainLoop()
if __name__ == '__main__':
main()
###################### 5秒钟自动弹出对话框
#!/usr/bin/python
#-*- encoding: utf-8 -*-
'''
Created on 2014年6月13日
@author: Administrator
'''
import wx
class Example(wx.Frame):
def __init__(self,*args,**kw):
super(Example,self).__init__(*args,**kw)
self.InitUI()
def InitUI(self):
wx.FutureCall(5000,self.ShowMessage)
self.SetSize((300,200))
self.Centre()
self.Show(True)
def ShowMessage(self):
wx.MessageBox('Down Completed','Info',wx.OK|wx.ICON_INFORMATION)
def main():
ex = wx.App()
Example(None)
ex.MainLoop()
if __name__ == '__main__':
main()
####################### 菜单栏弹出对话框
#!/usr/bin/python
#-*- encoding: utf-8 -*-
'''
Created on 2014年6月13日
@author: Administrator
'''
import wx
class Example(wx.Frame):
def __init__(self,*args,**kw):
super(Example,self).__init__(*args,**kw)
self.InitUI()
def InitUI(self):
menubar = wx.MenuBar()
help = wx.Menu()
help.Append(100,'&About')
self.Bind(wx.EVT_MENU, self.OnAboutBox, id=100)
menubar.Append(help,'&Help')
self.SetMenuBar(menubar)
self.SetSize((300, 200))
self.SetTitle('About dialog box')
self.Centre()
self.Show(True)
def ShowMessage1(self,e):
dial = wx.MessageDialog(None,'Download completed','info',wx.OK)
dial.ShowModal()
def OnAboutBox(self,e):
print 'OnAboutBox+++'
description = """File Hunter is an advanced file manager for
the Unix operating system. Features include powerful built-in editor,
advanced search capabilities, powerful batch renaming, file comparison,
extensive archive handling and more.
"""
licence = """File Hunter is free software; you can redistribute
it and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
File Hunter is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details. You should have
received a copy of the GNU General Public License along with File Hunter;
if not, write to the Free Software Foundation, Inc., 59 Temple Place,
Suite 330, Boston, MA 02111-1307 USA"""
info = wx.AboutDialogInfo()
info.SetIcon(wx.Icon('exit.png',wx.BITMAP_TYPE_PNG))
info.SetVersion('2.0')
info.SetDescription(description)
info.SetCopyright('(C) 2007 - 2011 Jan Bodnar')
info.SetWebSite('http://www.zetcode.com')
info.SetLicence(licence)
info.AddDeveloper('Jan Bodnar')
info.AddDocWriter('Jan Bodnar')
info.AddArtist('The Tango crew')
info.AddTranslator('Jan Bodnar')
wx.AboutBox(info)
def main():
ex = wx.App()
Example(None)
ex.MainLoop()
if __name__ == '__main__':
main()