About this question
I want my script to wait until the user presses any key. How do I do that?
I want my script to wait until the user presses any key. How do I do that?
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask Python Expert
Answered on Jan 12, 2021
If you are using Python 3 version then you can use the following syntax to make a wait key:-
input("Press Enter to continue...")
If you are using Python 2, you should use raw_input(), as input(prompt) is equivalent to eval(raw_input(prompt)):
raw_input("Press Enter to continue...")
All these methods only wait for a user to python press any key to continue, so you might want to use msvcrt which works in Windows/DOS only. The msvcrt module gives you access to a number of functions in the Microsoft Visual C/C++ Runtime Library (MSVCRT)):
import msvcrt as m
def wait(): m.getch()So you can use it to make a program for a wait keypress.
Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Most-read guides across JanBask
Common Python interview questions, answered
Guides, tips and career advice on Python from JanBask experts.
Python How to Become a Python Developer: A Step-by-Step Guide for Beginners
Discover how to become a Python Developer via a practical 7-step guide build projects, maintain clean code, practice daily, and…
Python PCEP Certification Guide: Entry-Level Python Programmer Certification
Explore this PCEP certification guide for insights on cost, exam format, passing score, application, training, and study tips.…
Python Top 50+ Python Projects ideas for Beginners to Advanced
Discover innovative Python project ideas, explore advanced Python projects, and find good Python projects for beginners and…
Python How To Comment Out Multiple Lines In Python Like A Pro
Commenting out code is a common practice among programmers. It allows you to temporarily disable parts of your code without…