[Python] Why is nothing drawn in Pygame at all?

Discussão em 'Python' iniciado por Stack, Agosto 2, 2025.

  1. Stack

    Stack Membro Participativo

    I have started a new project in python using Pygame and for the background I want the bottom half filled with gray and the top black. I have used rect drawing in projects before, but for some reason it seems to be broken? I don't know what I am doing wrong.

    The weirdest thing is that the result is different every time I run the program. Sometimes there is only a black screen and sometimes a gray rectangle covers part of the screen, but never half of the screen.

    import pygame, sys
    from pygame.locals import *
    pygame.init()

    DISPLAY = pygame.display.set_mode((800, 800))
    pygame.display.set_caption("thing")
    pygame.draw.rect(DISPLAY, (200, 200, 200), pygame.Rect(0, 400, 800, 400))

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

    Continue reading...

Compartilhe esta Página