1

I'm learning how to use pygame, and I'm just trying to open up a window for the game I'm creating.

The program compiles fine, and I tried drawing a circle to see if that would change anything but in both scenarios I still just get a blank window that freezes. My computer has plenty of storage space and only 2 applications open, and yet this is the only application that is freezing.

import pygame
pygame.init()

window = pygame.display.set_mode((500, 500))

I have to force quit Python because it stops responding. I have Python version 3.7.4 and Pygame version 1.9.6.

Any advice?

1737973
  • 159
  • 18
  • 42
  • 1
    It freezes because you don't handle any events. One event you should always handle is the `pygame.QUIT` event, which is when the user presses the close button on the top corner. [Here](https://stackoverflow.com/a/44256668/6486738) is more information. – Ted Klein Bergman Aug 25 '19 at 02:30

1 Answers1

2

A minimal, typical PyGame application

See also Python Pygame Introduction

Simple example, which draws a red circle in the center of the window: repl.it/@Rabbid76/PyGame-MinimalApplicationLoop

import pygame

pygame.init()
window = pygame.display.set_mode((500, 500))

# main application loop
run = True
while run:

    # event loop
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    # clear the display
    window.fill(0)

    # draw the scene   
    pygame.draw.circle(window, (255, 0, 0), (250, 250), 100)

    # update the display
    pygame.display.flip()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • 1
    Thank you! My program works now. I know this was a very basic question so I appreciate you being patient with me since I'm new to Python :) – i'm confused Aug 29 '19 at 10:16
  • I tried your code and when i try to close the window in the X button, it always freezes! I'm using Python 3.7.7 and Pygame 1.9.6 on Thonny 3.2.7. Actually all the pygame codes that i tried so far, it happends the same thing!!! – Pedro Figueiredo Jun 09 '20 at 15:46