1,105,263 Community Members

How to put a Pause in a Program

Member Avatar
usdblades
Newbie Poster
13 posts since Sep 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
woooee
Posting Maven
2,792 posts since Dec 2006
Reputation Points: 783 [?]
Q&As Helped to Solve: 836 [?]
Skill Endorsements: 12 [?]
 
0
 

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

Member Avatar
usdblades
Newbie Poster
13 posts since Sep 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
>>> print "hello World"

raw_input("Press ENTER to exit")

That is all I have for my code

Member Avatar
ZZucker
Practically a Posting Shark
828 posts since Jan 2008
Reputation Points: 313 [?]
Q&As Helped to Solve: 89 [?]
Skill Endorsements: 2 [?]
 
0
 
Member Avatar
woooee
Posting Maven
2,792 posts since Dec 2006
Reputation Points: 783 [?]
Q&As Helped to Solve: 836 [?]
Skill Endorsements: 12 [?]
 
0
 
>>> 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.

Member Avatar
usdblades
Newbie Poster
13 posts since Sep 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
woooee
Posting Maven
2,792 posts since Dec 2006
Reputation Points: 783 [?]
Q&As Helped to Solve: 836 [?]
Skill Endorsements: 12 [?]
 
0
 

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"
Member Avatar
usdblades
Newbie Poster
13 posts since Sep 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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"

Member Avatar
woooee
Posting Maven
2,792 posts since Dec 2006
Reputation Points: 783 [?]
Q&As Helped to Solve: 836 [?]
Skill Endorsements: 12 [?]
 
0
 

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

Member Avatar
usdblades
Newbie Poster
13 posts since Sep 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Question Answered as of 5 Years Ago by woooee and ZZucker
Member Avatar
dekalbxxx
Newbie Poster
4 posts since Dec 2010
Reputation Points: 6 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article