Posted in Python onFebruary 27, 2019
本文实例为大家分享了基于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()
效果如下:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。
基于wxPython的GUI实现输入对话框(1)
- Author -
网海水手声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@