[wxPython-users] masked text controls?

Will Sadkin WSadkin at Parlancecorp.com
Mon Nov 6 14:01:47 PST 2006


John Salerno wrote:
> I was looking through the demo and noticed some pretty nice masked
> text controls, for things like phone numbers, SS#, etc. But I'm not
> sure how to use them. Is there a class I can use to get this
> functionality, or were these things designed just for the demo to
> show us what can be done? Would they have to be reimplemented to use
> them in our own app? 
> 
> Thanks.

I've tried to give useful examples within the demos (that's what they're 
for, after all...)  I'm curious as to what is unclear; is the demo
as constructed too difficult to understand?  

At the simplest, you should be able to do something like:

 phonectl = wx.lib.masked.TextCtrl(self, -1, "", autoformat="USPHONEFULL")

and it will automatically set up the control for a phone number.
(The complete list of current autoformats is shown in the demo, but
they're just a shorthand for a set of parameters to the regular control...)
But it's easy to "roll your own;" eg:

 ssnctl = wx.lib.masked.TextCtrl(self, -1, "", 
					   mask="###-##-####", 
					   formatcodes="F",
					   validRegex="\d{3}-\d{2}-\d{4}")

The mask says "3 digits, hyphen then 2 digits, then hyphen, then 4 digits."
The formatcodes value means "fit control to the mask", and the 
validRegex is basically the same as the mask, but essentially allows 
the control to colorize as yellow (baad) on an incomplete value.
(The demo has an overview section for the masked edit controls 
that provides extensive documentation on these controls, as they are 
a "swiss army knife" of functionality...)

Hope this helps,
/Will Sadkin
Author, lib.masked




More information about the wxpython-users mailing list