3

How do I do user input in Python where I don't want the user to have to press enter in the console? In this case, it's opening a pdf. I want it to say something like

"PDF will automatically open. Press to view in a file browser or q to quit the program"

How can I make it so that the user doesn't have to hit enter, and the input won't show up onscreen? As soon as the user hits q, I want the program to exit.

As far as I know, both input() and raw_input require the user to hit enter.

Thanks!

evamvid

evamvid
  • 831
  • 6
  • 18
  • 40

1 Answers1

3

It varies by operating system. In answer to this stackoverflow question, you can see a recipe to read one character from STDIN on either unix or windows.

I haven't used it, but there is also the getch python pypi package you could try.

Community
  • 1
  • 1
Matt Anderson
  • 19,311
  • 11
  • 41
  • 57