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 Answer
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