I'm trying to write my first validator for wxPython. I want to check the TextCtrl value and change its background color based on whether or not it's numeric. It kind of works, except the event triggers before the current character is actually put in, so the validation is always one character behind. Here's my code:
class Validate_Numeric ( wx . PyValidator ):
def __init__ ( Self ):
wx . PyValidator . __init__ ( Self )
Self . Bind ( wx . EVT_TEXT, Self . On_Text_Change )
def Clone ( Self ):
return Validate_Numeric ()
def On_Text_Change ( Self, Event ):
TextCtrl = Self . GetWindow ()
Text = TextCtrl . GetValue ()
if Text . isdigit() or Text == "":
TextCtrl . SetBackgroundColour ( "White" )
else :
TextCtrl . SetBackgroundColour ( "Pink" )
Event . Skip ()
Questionable_TextCtrl = wx . TextCtrl ( Self, wx . ID_ANY, validator = Validate_Numeric () )
I've also tried EVT_CHAR and EVT_KEY_UP, but they all behave the same way. Does anybody know what I can do to validate the text after the text is updated?
Thanks!