[visionegg] Re: Terminating a While Loop
- From: Mark Halko <mhalko@xxxxxx>
- To: visionegg@xxxxxxxxxxxxx
- Date: Tue, 17 Jul 2007 13:52:21 -0400
How about something as simple as:
quit_now = False
pause = False
while not quit_now:
if not pause :
p.go()
for event in pygame.event.get():
if event.type == pygame.locals.KEYDOWN :
if event.key == pygame.locals.K_ESCAPE :
quit_now = True
if event.key == pygame.locals.K_SPACE :
pause = not pause
You could also set quit_now to True to quit if you reach some
criterion level from your experiment.
Mark
On Jul 17, 2007, at 1:14 PM, Maher, Jeffrey wrote:
Hello,
Im currently working on the following code trying to determine a
way to exit a while loop before the criteria is satisfied.
i=0
while i<eval(self.number.get()):
p.go
i=i+1
My goal is to set it to a certain key that will either pause the
program, and then resume it once pressed again, or have it exit the
program all-together, either/or would be acceptable.
I had tried setting it to the "esc" key by doing the following code
that I found while searching for an answer:
if msvcrt.kbhit() and msvcrt.getch() == chr(27):
break
But that just causes the program to fail to start up.
I have also tried:
for event in pygame.event.get():
if event.type == pygame.locals.KEYDOWN:
if event.key == pygame.locals.K_ESCAPE:
sys.exit()
But this again just causes the program to fail to start up.
Any suggestions would be greatly appreciated.
-Jeff
======================================
The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html
======================================
The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html
- Follow-Ups:
- [visionegg] Re: Terminating a While Loop
- From: Maher, Jeffrey
- References:
- [visionegg] Terminating a While Loop
- From: Maher, Jeffrey
Other related posts:
- » [visionegg] Terminating a While Loop
- » [visionegg] Re: Terminating a While Loop
- » [visionegg] Re: Terminating a While Loop
- » [visionegg] Re: Terminating a While Loop
- » [visionegg] Re: Terminating a While Loop
Hello,Im currently working on the following code trying to determine a way to exit a while loop before the criteria is satisfied.
i=0
while i<eval(self.number.get()):
p.go
i=i+1
My goal is to set it to a certain key that will either pause the
program, and then resume it once pressed again, or have it exit the
program all-together, either/or would be acceptable.
I had tried setting it to the "esc" key by doing the following code that I found while searching for an answer:
if msvcrt.kbhit() and msvcrt.getch() == chr(27):
break
But that just causes the program to fail to start up.
I have also tried:
for event in pygame.event.get():
if event.type == pygame.locals.KEYDOWN:
if event.key == pygame.locals.K_ESCAPE:
sys.exit()
But this again just causes the program to fail to start up.
Any suggestions would be greatly appreciated.
-Jeff
======================================
The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html
- [visionegg] Re: Terminating a While Loop
- From: Maher, Jeffrey
- [visionegg] Terminating a While Loop
- From: Maher, Jeffrey