[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Fwd: [pygame] Is there an InputBox function in pygame/python?
It gave me an error (@ Daniel's solution): global name upper not defined...?
---------- Forwarded message ----------
From: Daniel Dornhardt <frozensound@xxxxxx>
Date: Apr 27, 2005 3:12 PM
Subject: Re: [pygame] Is there an InputBox function in pygame/python?
To: pygame-users@xxxxxxxx
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.