[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Is there an InputBox function in pygame/python?



I'll not finish my input field class this evening if you don't absolutely need it anymore, D. Hartley.

You could make the input box a little bit safer if you change

elif inkey <= 127:

to

<code>

elif (inkey >= K_a and inkey <= K_z) or \
     (inkey >= K_0 and inkey <= K_9) or \
     (inkey == K_AT):

</code>


You'll have to put any additional characters you want to allow into the if, eg. put


(inkey == K_PLUS) or \

after (inkey >= K_0 and inkey <= K_9) or \ to allow the user to enter a plus ('+').

the K_AT is an example on how to do it. You could just leave it out, but don't forget to remove the 'or \ ' from the line before and replace it with an ':' .

It's just a safety measure, for i don't know what'll happen with the code if maybe 'tab' is pressed or whatever else may happen.

maybe just the Keys and the numbers will be enough to get on with it?