I am working on an RPG in pygame/python. I have made a char. creator that allows you to customize the player. Now I am looking for a way to prompt for a name on-screen. I don't want it to make a box, just print what the user is typing in a specific area (see picture). Thanks for help.
http://ubuntuone.com/3HdzOKroopUEf1YxqNnbFM <-----Picture (only looks blue through the link)
You can capture the events and if event.type == KEYDOWN, then check for event.key to get which key is the user pressing. Then you can add it to a text variable and show it on the screen.
You could also use EzText. It is a module that basically does what FRJA describes for you. There are plenty of other modules if you google "pygame text input." Here is EzText's example code:
I have recently written another module that makes it even easier to insert text. You simply create a
TextInput
-object, then feed it with events every frame of your game and finally retreive the rendered surface usingget_surface()
.Here's an example program that demonstrates how to use it:
If you want to process the user input after he pressed
return
, simply wait until theupdate()
-method returnsTrue
:More detailed information and the source code can be found on [my github page](my github page.