'Pygame window is not responding after just making it

I wanted to make a game using pygame and I started my code making the pygame window

import pygame
pygame.init()
pygame.display.set_mode((1500, 1000))

But every time I run the program, my pygame window does not respond. Does anyone know what is happening, this did happen to me on previous codes too but it wasn't all the time like it is now



Solution 1:[1]

you need a game loop to start the game and you need events to work on. for python code i suggest:

import pygame
pygame.init()
pygame.display.set_mode((1500, 1000))
start_game = True
while start_game:
    print("Game Started!")

and for the events you can use this code in the while loop:

for event in pygame.event.get():
    if event.type == pygame.MOUSEBUTTONUP:
        print("mouse button up pressed")

the source of this code is : RipTutorial

Solution 2:[2]

I assume that by 'my pygame window does not respond' you mean that you believe the window is not displaying. I think that you are just missing it because it is closing too quickly.

The window does display, but because your program ends right after you create the window, the window is immediately closed again. This is likely just happening so quickly that you are not noticing it. If you want to see this, then just put a call to sleep after opening the window and you will see the window sit there until the sleep expires and then it will close.

If you do not mean that and you are seeing the window but expecting it to respond, then I do not understand what you expect it to respond to. You do not have any code that tries to make it respond to anything.

EDIT:
I just noticed that @AnassABEA suggests that in a comment under his answer, though not in his answer. @AnassABEA you should update your answer to include this since I believe that is the actual answer to his question, not the missing event loop.

Solution 3:[3]

Add this below to your code:

run = True
while run:
for event in pygame.event.get():
    if event.type == pygame.QUIT:
        run = False
pygame.quit()

Lines 4 to 5 of the code are for closing pygame when the window is closed.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anass ABEA
Solution 2
Solution 3 Ethan