Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that you don't process pygame's event queue. You should simple call <code>pygame.event.pump()</code> at the end of your loop and then your code works fine:</p> <pre><code>... while not done: clock.tick(60) keyState = pygame.key.get_pressed() if keyState[pygame.K_ESCAPE]: print('\nGame Shuting Down!') done = True pygame.event.pump() # process event queue </code></pre> <p>From the <a href="http://www.pygame.org/docs/ref/event.html#pygame.event.pump">docs</a> (emphasis mine):</p> <blockquote> <p><strong>pygame.event.pump()</strong> </p> <p><em>internally process pygame event handlers</em> </p> <p><code>pump() -&gt; None</code> </p> <p><em><strong>For each frame of your game, you will need to make some sort of call to the event queue. This ensures your program can internally interact with the rest of the operating system.</em></strong> If you are not using other event functions in your game, you should call pygame.event.pump() to allow pygame to handle internal actions.</p> <p>This function is not necessary if your program is consistently processing events on the queue through the other pygame.event functions.</p> <p>There are important things that must be dealt with internally in the event queue. The main window may need to be repainted or respond to the system. <strong><em>If you fail to make a call to the event queue for too long, the system may decide your program has locked up</em></strong>.</p> </blockquote> <p>Note that you don't have to do this if you just call <code>pygame.event.get()</code> anywhere in your main-loop; if you do not, you should probably call <code>pygame.event.clear()</code> so the event queue will not fill up.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload