What about this?
try:
cutoff = float(cutoff)
except ValueError:
dlg = wx.MessageDialog(self,"Cutoff must be float","",style=style)
dlg.ShowModal()
dlg.Destroy()
···
-----Mensaje original-----
De: Jeffrey O'Neill [mailto:jco8@cornell.edu]
Enviado el: Jueves, 08 de Enero de 2004 15:34
Para: wxpython-users@lists.wxwindows.org
Asunto: [wxPython-users] validation for float input
Hello,
I'm a newbie, but I've succeeded in getting a decent application up and
running (http://stv.sourceforge.net), thanks to the extensive examples that
come with wxPython. I have a question about validating user input.
In my app I ask the user for a float. To validate, I override the default
OK button processing in the dialog. Here is an example for making sure
that the user entered a float:
def OnOK(self, event):
if re.search("^\s*(\d+|\d*\.\d+|\d+\.\d*)\s*$", self.Cutoff):
event.Skip()
else:
dlg = wx.MessageDialog(self.Cutoff must be a float.",
"", wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
This seems easier than using other validation methods. I tried the masked
text controls, but I don't like how the control is initialized with spaces.
Any comments on the above?
Jeff