Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pygame window keeps crashing with no error message

My program appears to run fine in the "python shell" but the pygame window opens and stays on a blank screen not showing anything. any interaction with the pygame window crashes it, making it stop responding and asking if I would like to close it or not.
My aim was to make a red box with two black lines making an x in it to represent the red exit button on most computer programs.
I’m new to python and have been learning from programarcadegames.com. I’ve tried to copy and paste their code into an empty python document and it runs fine, I don’t think my program does anything different in terms of the admin, yet it refuses to run.

Any advice would be appreciated whether you’re solving the overall problem or not, as I’m still quite new ’round these parts, 🙂

Here is the program:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

# Imports
import pygame
pygame.init()
import math
import sys
import os


# Setting variables and constants
PI = (math.pi)
WHITE = (255, 255, 255)
LYELLOW = (255, 255, 165)
# (Other colours removed for simplicity)

size = (1050, 750)
done = False
page = 0

test = 0


# Other admin
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Coursework Program, Benjamin Youell-Wright")
clock = pygame.time.Clock()


# Main Program
while done == False:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True


    while page == 0:
        test = 0
        
    
    while page == 1:
        test = 0
        
    
    while page == 2:
        test = 0
        
    
    while page == 3:
        test = 0
        
    
    while page == 4:
        test = 0
    
    
    screen.fill(WHITE)

    pygame.draw.rect(screen, RED,[775,595,20,20],2)
    
    pygame.draw.line(screen, BLACK, [779, 579], [791, 591], 1)
    pygame.draw.line(screen, BLACK, [779, 579], [791, 591], 1)
    
    pygame.display.flip()
    
    clock.tick(20)
    
pygame.quit()

>Solution :

You have a while loop inside your main loop that runs infinitely.

  while page == 0:
    test = 0

This just keeps setting test to 0 forever. You never actually reach the point where you flip the display. Remove these while loops and it should work.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading