How to save input from a text box to a variable in python?

378 views Asked by At

I'm creating a simple game to try to learn pygame, and I currently have a game where the user controls a car and has to dodge trucks on a highway.

The game starts off pretty slowly, but I want to add an input box for the user to set their own starting speed.

I know how to make working buttons, but I would rather have a text input that saves to a variable as an integer.

Can anyone help with this?

1

There are 1 answers

0
HariUserX On BEST ANSWER

you can use inputbox form pygame.

refer link

Then use:

inputbox.ask(screen, "question")

This will return string which can be casted to int