3

I'm writing this because, out of nowhere, my pygame program has started acting up. I'm no stranger to pygame and I'd say I know it better than most. I've been using it for years and out of nowhere this bug, or whatever it is, has me stumped.

The problem: Upon pressing the minimize button the screen (that is to say, the pygame.display object) goes completely blank (grey). It won't display anything until an update is called, and when that update is called it well redraw everything that was previously on it- however it will draw a transparent blue rectangle over everything.

My screen looks like this upon boot up:

My screen looks like this upon boot up

After minimizing and restoring, it looks like this:

After minimizing and restoring, it looks like this

After the next update is called, I get this:

After the next update is called, I get this

What makes this a true headscratcher though is this. I figured it was about time for an update anyway, so I wiped my drive reinstalled my entire OS, before putting in a fresh install of python(3.7 from 3.5) and pygame(1.9.2 from something less). So this system is out-of-the-box mint.

I've been using pygame for years now. I know I can code my way around this (probably by just drawing everything from prior to the minimization) but that is going to add more complexity and overhead than I'm willing to offer- esspecially since there is obviously something broken happening.

import pygame, sys
pygame.init()

Screen = pygame.display.set_mode( ( 1200, 700 ), pygame.RESIZABLE, 32 )

pygame.draw.circle( Screen, ( 200, 200, 200 ), ( 600, 350 ), 300, 0 )

pygame.display.update()

while True:

  for event in pygame.event.get():

    if event.type == pygame.QUIT: pygame.quit()

    pygame.display.update()
Micheal O'Dwyer
  • 1,237
  • 1
  • 16
  • 26
Lucas Young
  • 119
  • 1
  • 9

1 Answers1

0

You are likely getting this error, because you are not specifying a background color, and, as a result, your OS can use a default color, when the window is not updated.

While I cannot reproduce the problem on my computer (which runs Windows 7), I am sure that just calling screen.fill(), and a little code movement, should solve the problem.

  • I removed the extra parameters passed to pygame.display.set_mode(), because they seem unnecessary to me.

  • I removed the call to pygame.draw.circle(), into the while loop, so that the circle is drawn every frame. I removed the first pygame.display.update() line, because this line should generally go at the end of the while loop, after all drawing has been done.

  • I'm not sure if the code you posted indented the second pygame.display.update() correctly, but this line should not be ran inside the for loop, but instead, at the end of each iteration of the while loop. So, I moved it back one level of indentation.

  • And finally, I added in the line screen.fill((0, 0, 0)) which fills the screen with black. This line must come before any lines of code which draw stuff to the screen, because then we wouldn't be able to see what was just drawn.

That line should stop the blue background which Mac is defaulting to.

Here is the fixed code:

import pygame, sys
pygame.init()

screen = pygame.display.set_mode((1200, 700))

while True:

    for event in pygame.event.get():

        if event.type == pygame.QUIT: 
            pygame.quit()
            quit()

    screen.fill((0, 0, 0))
    pygame.draw.circle( screen, ( 200, 200, 200 ), ( 600, 350 ), 300, 0 )
    pygame.display.update()

I hope this answer helped you! Please let me know if this solution worked for you, and if you have any further questions, feel free to leave a comment below!

Micheal O'Dwyer
  • 1,237
  • 1
  • 16
  • 26