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

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



try (not tested):

-----------------------

from string import upper

   inkey = get_key()
   if inkey == K_BACKSPACE:
     current_string = current_string[0:-1]
   elif inkey == K_RETURN:
     break
   elif inkey == K_MINUS:
     current_string.append("_")

<changed>

   elif inkey <= 127:
     newchar = chr(inkey))
     if pygame.key.get_mods() & KMOD_SHIFT:
       newchar = upper(newchar)
     current_string.append(newchar)

</changed>


it tests is shift is pressed and converts the input to an uppercase letter.

I don't know if you'll run into problems if other keys then numbers and letters are pressed, eg. F1:F12 or so, if you have any problems, report back.