简体   繁体   中英

When i make a pygame game and hover over it, the cursor turns into the loading thing

When i make a pygame game and hover over it, the cursor turns into the loading thing, that means I can't resize the window, or if i were to make buttons i wouldn't be able to use them... Help? Here's my code.

import pygame
import random
import time
import os

from pygame.locals import *

red = (255,0,0)
white = (255,255,255)
black = (0,0,0)
green = (0,255,0)
blue = (0,0,255)

pygame.init()

background_colour = (white)

(width, height) = (800, 600)

screen = pygame.display.set_mode((width, height), pygame.RESIZABLE)

screen.fill(background_colour)

while True:
    pygame.draw.circle(screen,
                       (random.randint(0,255),
                        random.randint(0,255),random.randint(0,255)),
                       (random.randint(0,800),random.randint(0,600)), 20)
    pygame.display.flip()

So yeah, it always happens with pygame.

Add this in top of your while. This for runs throught events and if

event.type == pygame.QUIT 

This means that you presed cross for closing the window and window will be closed. You can catch all pygame events like this.

while True: #your wile

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
   #your code 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM