wxPython:文本对话框TextEntryDialog

最后更新于:2022-04-01 19:41:18

本节看看单行文本对话框的使用,先看函数原型: wxTextEntryDialog([wxWindow](http://www.cnblogs.com/dyx1024/admin/)* parent, const [wxString](http://www.cnblogs.com/dyx1024/admin/)& message, const [wxString](http://www.cnblogs.com/dyx1024/admin/)& caption = "Please enter text", const[wxString](http://www.cnblogs.com/dyx1024/admin/)& defaultValue = "", long style = wxOK | wxCANCEL | wxCENTRE, const [wxPoint](http://www.cnblogs.com/dyx1024/admin/)& pos = wxDefaultPosition) 其支持的方法有: wxTextEntryDialog::GetValue  获取文档框中的值 wxTextEntryDialog::SetValue  设置文本框中的值 wxTextEntryDialog::ShowModal 模态显示对话框 其它参数不详细做介绍。 看一下实例: ~~~ #!/usr/bin/env python # -*- coding: utf-8 -*- ''' Function:常用对话框实例 Input:NONE Output: NONE author: socrates blog:http://www.cnblogs.com/dyx1024/ date:2012-07-07 ''' 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() # def OnCloseMe(self, event): dlg = wx.TextEntryDialog(None, u"请在下面文本框中输入内容:", u"文本输入框标题", u"默认内容") if dlg.ShowModal() == wx.ID_OK: message = dlg.GetValue() #获取文本框中输入的值 dlg_tip = wx.MessageDialog(None, message, u"标题信息", wx.OK | wx.ICON_INFORMATION) if dlg_tip.ShowModal() == wx.ID_OK: self.Close(True) dlg_tip.Destroy() dlg.Destroy() if __name__ == '__main__': app = wx.PySimpleApp() frame = MyFrame(parent = None, id = -1) frame.Show() app.MainLoop() ~~~ 测试: ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-06-08_5757935f341db.png) 点击OK后: ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-06-08_5757935f47085.png)
';