Regi
Regi

Reputation: 31

Get user input in Python 3 without pressing enter

Is there a way to take the users input without them having to press enter? I searched this question but most of the answers are for Python 2 or don't work.

I don't understand or this solution doesn't work: How to accept input without the need to press enter Python 3

Upvotes: 2

Views: 4213

Answers (1)

user11063427
user11063427

Reputation:

You can use msvcrt on windows to allow the user to enter one value, then enter it without needing to actually pres the enter key.

import msvcrt                    #You will need this.
your_variable = msvcrt.getch()   #Allows the user to enter a single value, 
                                 #then immediately enter it.

Side note: You cannot run this properly in the shell, just run it straight from your folder. Also, in case you're feeling lazy, you can use my module that I created here, if you use it and notice any errors, please let me know as it would help me get better at python. I hope I helped you!

Upvotes: 1

Related Questions