基于wxPython的GUI实现输入对话框(1)
时间:2021-01-15 11:15:24|栏目:Python代码|点击: 次
本文实例为大家分享了基于wxPython的GUI实现输入对话框的具体代码,供大家参考,具体内容如下
编程时,免不了要输入一些参数等,这时输入对话框就派上用处了:
#-*- coding:utf-8 -*- #~ #-------------------------------------------------------------------------------- #~ FileName=wxinputbox.py #~ Funciton:wx的输入对话框 #~ author:吴徐平 #~ Date:2013-04-28 #~ Email:539688300@qq.com #~ #-------------------------------------------------------------------------------- import wx class TextEntryDialog(wx.Dialog): def __init__(self, parent=None, title='Title', caption='Caption',size=(500, 200)): ''' #~ dialog = TextEntryDialog(parent=None, title=title,caption=caption,size=size) #~ dialog = TextEntryDialog() ''' style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER super(TextEntryDialog, self).__init__(parent, -1, title=title, style=style) self.text = wx.StaticText(self, -1, caption) self.input = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE) self.input.SetInitialSize(size) self.buttons = self.CreateButtonSizer(wx.OK|wx.CANCEL) self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.text, 0, wx.ALL, 5) self.sizer.Add(self.input, 1, wx.EXPAND|wx.ALL, 5) self.sizer.Add(self.buttons, 0, wx.EXPAND|wx.ALL, 5) self.SetSizerAndFit(self.sizer) self.Center() def SetValue(self, value): self.input.SetValue(value) def GetValue(self): return self.input.GetValue() def wxinputbox(Initialstring='Initial String',title='Title',caption='Caption',size=(500,200)): ''' #~ >>>stringvalue=wxinputbox(Initialstring='Initial String',title='Title',caption='Caption',size=(500,200)): #~ >>> stringvalue=wxinputbox() ''' app = wx.PySimpleApp() #~ dialog = TextEntryDialog(None, title=title,caption=caption,size=size) dialog = TextEntryDialog() dialog.SetValue(Initialstring) if dialog.ShowModal() == wx.ID_OK: stringvalue= dialog.GetValue() else: stringvalue='' dialog.Destroy() app.MainLoop() return stringvalue if __name__ == '__main__': #~ #使用wx的输入对话框 stringvalue=wxinputbox() print(stringvalue) #~ if __name__ == '__main__': #~ app = wx.PySimpleApp() #~ #使用wx自带的输入对话框 #~ dialog = wx.TextEntryDialog(None, 'Rules:', 'Edit rules', #~ style=wx.TE_MULTILINE|wx.OK|wx.CANCEL) #~ dialog.SetInitialSize((500,200)) #~ if dialog.ShowModal() == wx.ID_OK: #~ print 'OK' #~ dialog.Destroy() #~ app.MainLoop()
效果如下:
栏 目:Python代码
本文地址:http://www.codeinn.net/misctech/45710.html