user1027046
user1027046

Reputation: 293

how to pause a program until a button is pressed

I am using py2exe to make executable. I want to know how to pause the program until a button is pressed.. just like we do in C using system("pause");

As the program terminates automatically in windows, I need this tool.

Is there anything better than py2exe which does similar work ?

Upvotes: 2

Views: 22546

Answers (3)

Michelle Welcks
Michelle Welcks

Reputation: 3904

A quick code snippet to handle both Python 2 and 3:

# -*- coding: utf-8 -*-
import sys
python2 = sys.version_info[0] == 2
if python2:
    raw_input("Press ENTER to continue.")
else:
    input("Press ENTER to continue.")

Upvotes: 4

dmwangi
dmwangi

Reputation: 33

import os

Then in your code

os.system("pause")

Upvotes: -2

setrofim
setrofim

Reputation: 725

You can use raw_input in Python2, or input in Python 3

raw_input("Press Enter to terminate.")

Upvotes: 6

Related Questions