0

I have some simple code here that is not behaving as I expected:

import pygame,sys
from pygame.locals import *
pygame.init()
window = pygame.display.set_mode((1300,700))

while True:
    window.fill((0,0,0))

    pygame.display.update()
    #show black window, should happen before wait

    pygame.time.wait(2000)
    #program waits for 2 seconds, and then shows black window

    for event in pygame.event.get():
        if event.type==QUIT:
            pygame.quit()
            sys.exit(0)

The program waits for 2 seconds before updating the display and showing the black window. Why? Since python is an interpreted language, shouldnt pygame.display.update() happen before pygame.time.wait(2000)?

Johnny Dollard
  • 708
  • 3
  • 11
  • 26
  • display as default is black. So how do you know when it changes from black to black ? – furas Dec 22 '17 at 04:15
  • try to use events before `fill`. I susspect that on some systems it can use events to update screen. – furas Dec 22 '17 at 04:18
  • 1
    this "works for me". As @furas put it, try to insert a call to `pygame.event.pump()` before calling `wait`. – jsbueno Dec 22 '17 at 12:47
  • @jsbueno Thanks, that seems to work. I will do some more research into why. – Johnny Dollard Dec 28 '17 at 22:42
  • @furas My window is gray until I fill it with black. What kind of events should I put before fill to update the screen? – Johnny Dollard Dec 28 '17 at 22:43
  • 1
    on Linux (Mint) window is always black so I don't know what the problem is. Try `pygame.event.pump()` before `pygame.time.wait` or simply put `pygame.time.wait` after `for event in pygame.event.get():` I in code use `for event in pygame.event.get():` always directly after `while True`. – furas Dec 29 '17 at 00:15
  • @furas I am running a Mac, so that’s probably why it’s different. `pygame.event.pump()` works for me. I’ll move the `for event in pygame.event.get():` earlier in the program and see if that works without needing pump. Thanks! – Johnny Dollard Dec 30 '17 at 02:44

0 Answers0