[Tutor] Limiting Characters

Luke Paireepinart rabidpoobear at gmail.com
Mon Aug 21 21:48:27 CEST 2006


Marcus Dean Adams wrote:
>
> I’m fairly new to python, I’ve been dabbling in it for school and I 
> have a question.  I’ve written a few programs using graphical windows 
> with input boxes such as a stopwatch, temperature converter, etc.  
> I’ve always found a gui much prettier than command line.  Anyway, I 
> have limited the size of the input boxes to the number of digits I 
> wanted, but you can still put more digits than that in the box.  For 
> example, the temperature converter input box is only 3 digits wide, 
> however I can enter a 20 digit number if I want, it just only shows 3 
> digits at a time.  How can I actually limit the number of characters a 
> user can enter, and not just the size of the input box?
>
>
you can bind a callback for every key event and only add the key to the 
input box only if the length of the text currently in the inputbox is 
less than your target length.
you didn't say what GUI you're using so can't be of more help than that.
Alternatively, you can just truncate the extra digits so you have only 
3, but that's called 'unexpected behavior' as far as the user is concerned.
Sort of how my last name is 12 characters long, but on some apps that 
only have a 12 character array (with the actual length being 11 because
of the null terminator)  the last letter of my name gets truncated.  
This doesn't happen anymore, but I used to have everyone calling me
'paireepinar' because that's what was in the computer so they believed 
it.  Stupid old programs :)
>
> --
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.1.405 / Virus Database: 268.11.3/423 - Release Date: 8/18/2006
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>   



More information about the Tutor mailing list