Reputation: 67
So I am attempting to draw a chess board (the current code has nothing to do with chess boards, as I'm trying to debug my issue), and I'm running into an interesting issue with pygame.
import pygame
pygame.init()
clock = pygame.time.Clock()
window_width = 400
window_height = 400
display_window = pygame.display.set_mode((window_width, window_height))
. . .
def chess_game():
playing = True
while playing:
clock.tick(30)
# chess_board.draw()
pygame.draw.rect(display_window, (255, 0, 0), (0, 0, window_width, window_height))
pygame.draw.circle(display_window, (0, 255, 0), (100, 100), 20)
for event in pygame.event.get():
if event.type == pygame.QUIT:
playing = False
pygame.quit()
break
chess_game()
So when I run this code, I am expecting to get a red window with a green circle. Instead, I get a black screen. The strange thing I'm running into, however, is that if I drag the window off the screen (so that a portion of the window is outside of my desktop window), the portion of the window that is outside my desktop will be drawn correctly. See the image below.
As you can see, the red background and the circle are there, they just aren't visible unless I drag the window off the screen.
I don't think it's a pygame problem, as I built an actually functional program using similar code already. If this helps at all, I'm on a Windows 10 laptop using PyCharm.
Thanks!
Upvotes: 0
Views: 105
Reputation: 169075
You'll need to call
pygame.display.update()
on each frame. Dragging the window has the side effect of ensuring the newly "revealed" pixels are updated.
Upvotes: 2