基于wxPython的GUI实现输入对话框(1)
本文实例为大家分享了基于wxPython的GUI实现输入对话框的具体代码,供大家参考,具体内容如下
编程时,免不了要输入一些参数等,这时输入对话框就派上用处了:
#-*- coding:utf-8 -*- #~ #-------------------------------------------------------------------------------- #~ FileName=wxinputbox.py #~ Funciton:wx的输入对话框 #~ author:吴徐平 #~ Date:2013-04-28 #~ Email:[email protected] #~ #-------------------------------------------------------------------------------- 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()
效果如下:
相关推荐
tmj 2020-09-23
86417413 2020-11-25
83206733 2020-11-19
86276537 2020-11-19
83266337 2020-11-19
86256434 2020-11-17
zhouboxiao 2020-11-16
rise 2020-11-22
sssdssxss 2020-11-20
windle 2020-11-10
孙雪峰 2020-10-30
85477104 2020-11-17
xfcyhades 2020-11-20
liuxudong00 2020-11-19
cheidou 2020-11-19
gunhunti 2020-09-25
csdnYF 2020-11-15
达观数据 2020-11-11