I just started learning Python Last Night and I am curious of how to put a pause at the end.

I did the Famous Hello World Program and when saved and Executed it seems like it runs and closes before I can even read the text.

I tried

raw_input("Press ENTER to exit")

Not sure if this matters but I am Creating my programs in Notepad (notepad.exe). I save the File as something.py

Saves just Fine and when I run the Program it opens a screen for less than a second.

Recommended Answers

All 11 Replies

First try using idle instead of Notepad. You can enter, save, and run the program from Idle. It should be under the python and then idlelib directories, and is something like Idle.py-I don't remember. That will solve the immediate problem. Your solution should work also, so it may be that it is in a part of the program that is not reached. Post the entire program if you want more info. To answer the question directly, use time.sleep(seconds)

import time
print "Starting Program"
time.sleep(2)
print "2 seconds are up already"

Edit: Here is a link to the python docs. See the "Starting IDLE on Windows" section and welcome to Python. http://www.python.org/idle/doc/idle2.html

>>> print "hello World"

raw_input("Press ENTER to exit")

That is all I have for my code

>>> print "hello World"

raw_input("Press ENTER to exit")

That is all I have for my code

Works for me on Linux. Try

print "Hello World"
raw_input("Press ENTER to exit")
raw_input("Press ENTER to exit")
raw_input("Press ENTER to exit")

It may be that when you enter the program name on the command line, it's using that Enter for the raw input. (Being a Linux person I would just say that MS Windows is weird.) Anyway, post back with the solution if you find it. Someone else will surely be searching for that in the future.

Nope still Closes right away. I even used the IDLE Python(GUI) saved it and tried running and still closes

I took a look at that Page Zzucker I did what it said and still having the issue

Run it from Idle. There is a "run" option in the menu. Idle will display the output. So enter the code in Idle, save it in Idle, click on the "run" option in the menu, and look at the output all within Idle. Finally, you can try storing your input to a variable but I doubt that will help.

print "Hello World"
x = raw_input("Press Enter")
print "Bye Bye"

Alright I tried that and It Printed Hello World and then that was it nothing else. I then tried taking out x = to see if maybe it would pause but to no success. It did not even get to

print "Bye Bye"

You should have also seen "Press Enter" or whatever, then you hit the Enter key, and afterwards you should see "Bye, "Bye" on the screen. If that doesn't work, I would strongly suggest reinstalling Python as it appears there is a problem. Activestate has the easiest installer for a new user IMHO. http://aspn.activestate.com/ASPN/Downloads/ActivePython

Freaking Sweet. It works :) Freaking ehh Yeahhea. oh THank you woooee for your patients and help.

How do you pause a program so that an input window does not appear on a graphics canvas?

Try the input() method:
eg 1:
input("Press 'Enter' to exit")
eg 2:
name = input("What is your name? ")
print("Have a nice day ", name)
input("Press Enter to exit! ;-)")
BTW. the raw_input() method doesn't work for me no matter how I try to use it (Idle Shell 3.9.6 on Windows 8.1).
Also, the print() method doesn't work without the parenthesis.
So I guess it's down to what version of Python you use and it's a pain in the bottom :-D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.