0

I am new to PyGame. I want my PyGame program to ask me for input on the GUI screen so when you execute the program you get the shell and PyGame, I don't want to give the input to the shell. I want to give it to the PyGame GUI. My input can be strings or ints. How can I do this?

1
  • @David Foerster Yeah, i know, but the guys at the pygame IRC said it was OS depending.
    – TAL
    Dec 5, 2016 at 13:13

1 Answer 1

3

EzText is a simple, easy to use library for text input in PyGame. The runtime is extremely easy to include into your own program. You can clone the EzText project into a local directory with the following commands:

sudo apt install git
git clone https://github.com/ffavela/eztext.git

If you press Return it will store the input string in a variable, if you modify the source code by adding the string which is marked as bold text.

def update(self, events):
    """ Update the input based on passed events """ 
    for event in events: 
        if event.type == KEYUP: 
            if event.key == K_LSHIFT or event.key == K_RSHIFT: self.shifted = False 
        if event.type == KEYDOWN: 
            if event.key == K_BACKSPACE: self.value = self.value[:-1] 
            elif event.key == K_LSHIFT or event.key == K_RSHIFT: self.shifted = True 
            elif event.key == K_SPACE: self.value += ' ' 
            elif event.key == K_RETURN: return self.value
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.