Search code examples
pythonpygame

Pygame screen.fill() not filling up the color properly


I've just started learning Pygame . I'm following this tutorial. I ran the following program but it shows black color instead of blue :

import pygame

h = input("Enter the height of the window : ")
w = input("Enter the width of the window : ")
screen = pygame.display.set_mode((w,h))

running = True
while running:
    event = pygame.event.poll()
    if event.type == pygame.QUIT:
        running=0

screen.fill((0,0,1))
pygame.display.flip()

Solution

  • For Blue color, you should use 255 as the third element in the tuple, not 1.

    Example -

    while running:
        event = pygame.event.poll()
        if event.type == pygame.QUIT:
            running=0
        screen.fill((0,0,255))
        pygame.display.flip()