Trouble with New Python - pygame install and test


mainframetech

Still Fresh
Joined
Nov 17, 2015
Messages
2
 Hi!  I'm new as of today (Monday, 11/16/15)


            I have recently downloaded Python 3.5 and also pygames 1.9.2a0 to go with it using pip3.5.exe to download.  I tried a simple sample program (colorviewer.py from Andy Harris’ book ‘Game Programming’).  The window appears and the color cursors will operate properly, telling me that the event loop is working.  However, when closing the window with the ‘X’ at the upper right of the window (the normal ‘close’ command), the program just hangs and does nothing.  I tried it with no change to the program, and then added on the line to test pygame.QUIT  the K_ESCAPE key and that fails too.  I'm running on a large Dell studio machine with 3 gig memory and plenty of disk space.  I'm using Windows 7.  Any ideas?


 


            Here’s the code:


while keepGoing:


    clock.tick(30)


   


    for event in pygame.event.get():


        if event.type == pygame.QUIT or event.type == pygame.K_ESCAPE:


            keepGoing = False


 


            I’m just beginning to learn Python & pygame, but I’m not a newbie to programming, having been a systems programmer using mainframe assembler and machine code languages for years.  I’ve written some Windows ‘C’ as well and generally understand the layout of the PC system in conversation with Windows programs, but this is a new environment for me.


            Any help is appreciated,
 
Wow! I didn't even notice that I was still subscribed to this forum! Almost a year since the last topic here. (Perhaps, given how dead this forum is, it ought to be removed.)

Anyway, mainframetech, this forum is focused on a handheld computer called the OpenPandora (and its successor, the upcoming Pyra), so this isn't the appropriate place to ask that question. I would recommend either this forum:

http://python-forum.org/

Or the Pygame mailing list:

http://pygame.org/wiki/info#Mailing%20List

Cheers! :)
 
onpon4 is absolutely right.


However, I'll just note that pygame.event.get() looks to be some sort of generator - you'll need for that to complete before that for loop will finish, and the while loop will test keepGoing again.  Try adding a 'break' after setting keepGoing to False to get immediately out of the for loop and back to that while test which will let you out.


Alternately, if it's just not sending the right events, print out the events you receive, and then you'll be able to tell what does get sent when you hit the close button.
 
However, I'll just note that pygame.event.get() looks to be some sort of generator - you'll need for that to complete before that for loop will finish, and the while loop will test keepGoing again. Try adding a 'break' after setting keepGoing to False to get immediately out of the for loop and back to that while test which will let you out.
No, pygame.event.get returns a list. Adding a break statement would cause events to be lost.

I think what's probably actually happening is just a problem Pygame has with IDLE where references kept by IDLE prevent the application from closing correctly:

http://www.pygame.org/wiki/FrequentlyAskedQuestions#In%20IDLE%20why%20does%20the%20Pygame%20window%20not%20close%20correctly?
 
Last edited by a moderator:
Back
Top