栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

wx.TextCtrl和wx.Validator

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

wx.TextCtrl和wx.Validator

这是wxWidgets的功能,在wxPython中未实现。

http://www.wxpython.org/docs/api/wx.TextValidator-
class.html-
找不到

而:

http://docs.wxwidgets.org/trunk/classwx_text_validator.html


http://docs.wxwidgets.org/stable/wx_wxtextvalidator.html

wxPython演示中有一个Validators演示:

import wxclass TextObjectValidator(wx.PyValidator):     """ This validator is used to ensure that the user has entered something         into the text object editor dialog's text field.     """     def __init__(self):         """ Standard constructor.         """         wx.PyValidator.__init__(self)     def Clone(self):         """ Standard cloner.  Note that every validator must implement the Clone() method.         """         return TextObjectValidator()     def Validate(self, win):         """ Validate the contents of the given text control.         """         textCtrl = self.GetWindow()         text = textCtrl.GetValue()         if len(text) == 0:  wx.MessageBox("A text object must contain some text!", "Error")  textCtrl.SetBackgroundColour("pink")  textCtrl.SetFocus()  textCtrl.Refresh()  return False         else:  textCtrl.SetBackgroundColour(      wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))  textCtrl.Refresh()  return True     def TransferToWindow(self):         """ Transfer data from validator to window.  The default implementation returns False, indicating that an error  occurred.  We simply return True, as we don't do any data transfer.         """         return True # Prevent wxDialog from complaining.     def TransferFromWindow(self):         """ Transfer data from window to validator.  The default implementation returns False, indicating that an error  occurred.  We simply return True, as we don't do any data transfer.         """         return True # Prevent wxDialog from complaining.#----------------------------------------------------------------------class TestValidateDialog(wx.Dialog):    def __init__(self, parent):        wx.Dialog.__init__(self, parent, -1, "Validated Dialog")        self.SetAutoLayout(True)        VSPACE = 10        fgs = wx.FlexGridSizer(0, 2)        fgs.Add((1,1));        fgs.Add(wx.StaticText(self, -1,       "These controls must have text entered into them.  Eachn"       "one has a validator that is checked when the Okayn"       "button is clicked."))        fgs.Add((1,VSPACE)); fgs.Add((1,VSPACE))        label = wx.StaticText(self, -1, "First: ")        fgs.Add(label, 0, wx.ALIGN_RIGHT|wx.CENTER)        fgs.Add(wx.TextCtrl(self, -1, "", validator = TextObjectValidator()))        fgs.Add((1,VSPACE)); fgs.Add((1,VSPACE))        label = wx.StaticText(self, -1, "Second: ")        fgs.Add(label, 0, wx.ALIGN_RIGHT|wx.CENTER)        fgs.Add(wx.TextCtrl(self, -1, "", validator = TextObjectValidator()))        buttons = wx.StdDialogButtonSizer() #wx.BoxSizer(wx.HORIZONTAL)        b = wx.Button(self, wx.ID_OK, "OK")        b.SetDefault()        buttons.AddButton(b)        buttons.AddButton(wx.Button(self, wx.ID_CANCEL, "Cancel"))        buttons.Realize()        border = wx.BoxSizer(wx.VERTICAL)        border.Add(fgs, 1, wx.GROW|wx.ALL, 25)        border.Add(buttons)        self.SetSizer(border)        border.Fit(self)        self.Layout()app = wx.App(redirect=False)f = wx.frame(parent=None)f.Show()dlg = TestValidateDialog(f)dlg.ShowModal()dlg.Destroy()app.MainLoop()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/640467.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号