Jonathan1609
Jonathan1609

Reputation: 1919

Changing default PyGame background from black to white

I am trying to change the default color from black to white. not to fill it. My current code where I fill it:

import pygame
pygame.init()

size = 600, 600

surface = pygame.display.set_mode(size, pygame.RESIZABLE)
surface.fill((255, 255, 255))

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

It works however it is being shown as black for a second and then it changes itself, and i am looking for a solution where in advance it starts with white background. Thanks in advance

Upvotes: 1

Views: 903

Answers (2)

Jonathan1609
Jonathan1609

Reputation: 1919

By @starbuck45 I used the flag pygame.HIDDEN.

import pygame
pygame.init()

size = 600, 600
surface = pygame.display.set_mode(size, pygame.RESIZABLE | pygame.HIDDEN)
surface.fill("white")
pygame.display.set_mode(size)

line = pygame.draw.line(surface, "black", (0, 0), (600, 600))


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

and it worked fine!

Upvotes: 1

MHP
MHP

Reputation: 362

Maybe this will help you

import pygame
pygame.init()

size = 600, 600

surface = pygame.display.set_mode(size, pygame.RESIZABLE)
surface.fill((255, 255, 255))

while True:
    surface.fill((255, 255, 255))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()
    pygame.display.update()

Upvotes: 1

Related Questions