Yes, that's what I want. Let me try it first, then I will tell you if it works for me or not. Thank you for your help.
Jenny
···
From: Raul Cota <cota@ucalgary.ca>
Reply-To: wxpython-users@lists.wxwindows.org
To: wxpython-users@lists.wxwindows.org
Subject: Re: [wxPython] how to erase the text?
Date: Tue, 26 Jun 2001 15:35:50 -0600I'm assuming that all you want is to keep the TextCtrl from getting more
than 4 characters.
If I'm right.... What I would do is....self.extension = wxTextCtrl(panel, ID_EXTENSION, "")
EVT_TEXT(self, ID_EXTENSION, self.check)
EVT_CHAR(self.extension, self.EvtChar)def EvtChar(self, event):
k = event.GetKeyCode()
if self.extension.GetLineLength(0) != 4:
event.Skip()
else:
# 8 = backspace
# 13 = enter
# 27 = esc
if k == 8 or k == 13 or k == 27:
event.Skip()
else:
#If the length is already 4, I don't write the line
#event.Skip() and the character is not written
print 'error'def check(self, event):
#Whatever you want here
passThe EVT_CHAR event is ran before the EVT_TEXT event. And if you don't
write the line event.Skip(), the EVT_TEXT event is not ran at all, thus
the character pressed won't appear on the text control.
In this example I aloud the "backspace", "enter", and "esc" keys to be
passes to the control even if the length of the control is already 4.
That way you can still edit the text.I use this set of events for something different (I give my own behavior
to an enter and the arrow keys) but I think it could help you if that's
what you are trying to do.qun liu wrote:
>
> Hi,
>
> I am trying to repaint the wxTextCtrl when the length of the input text is
> more than four, but Refresh() didn't work here. Could somebody give me any
> suggestion? Thanks.
>
> Jenny
>
> #------------------------------------------------------
> self.extension = wxTextCtrl(panel, ID_EXTENSION, "")
> EVT_TEXT(self, ID_EXTENSION, self.check)
> def check(self, event):
> text = self.extension.GetValue()
> if (len(text) > 4 ):
> print "error"
> self.extension.Refresh(true)
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
>
> _______________________________________________
> wxpython-users mailing list
> wxpython-users@lists.wxwindows.org
> http://lists.wxwindows.org/mailman/listinfo/wxpython-users_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com