I'm trying to change my background image color, but somehow it doesn't work.

I have provided my code below and hope you will be able to tell me how I should do this, and why my code didn't work.

import pygame

class Wooden_Boy:

    def __init__(self, win_game):

        self.screen = win_game.screen
        self.screen_rect = win_game.screen.get_rect()

        self.image = pygame.image.load("alien_invasion/images/wooden_boy.png").convert()
        self.image.set_colorkey((0, 0, 255))
        self.rect = self.image.get_rect()

        self.rect.center = self.screen_rect.center

    def blitme(self):
        self.screen.blit(self.image, self.rect)

This is my second code which is connected with wooden boy:

import sys
import pygame
from wooden_boy import Wooden_Boy

class Window:

    def __init__(self):


        self.screen = pygame.display.set_mode((1200, 800))
        pygame.display.set_caption("Pygame Window")

        self.boy = Wooden_Boy(self)

        self.bg_color = (0, 0, 255)

    def run_window(self):
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:



if __name__ == "__main__":
    win = Window()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.