Trying to use Pygame with the Python3 3.12.2

Hi guys!
I try to code a game with pygame, But when I run my code it just write back this line (on screenshot)
So, i clicked on the link but it drive me on 10 deferents web sites… Is some one know a way to fix it or I just need to download 10 files with is strange :thinking: (I just update pygame and Python3).
Thanks

You haven’t shared any code, so we can’t help you.

Please don’t post screenshots of text, use the preformatted text button in the editor instead. It’s the one that looks like this: </>

import time
import pygame
import random
pygame.font.init()
from game import Game
from player import Player

WIDTH, HEIGHT = 1400, 800
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Space War")

BG = pygame.transform.scale(pygame.image.load("15600108-paysage-spatial-de-galaxie-de-dessin-anime-fond-de-vecteur-vectoriel.jpg"), (WIDTH, HEIGHT))

game = Gam#()

#STAR_WIDTH = 10
#STAR_HEIGHT = 20
#STAR_VEL = 3

FONT = pygame.font.SysFont("comicsans", 30)

def draw(player, elapsed_time, stars):
    WIN.blit(BG, (0, 0))

    time_text = FONT.render(f"Time: {round(elapsed_time)}s", 1, "white")
    WIN.blit(time_text, (10, 10))

    #pygame.draw.rect(WIN, "red", player)
    WIN.blit(game.player.image, game.player.rect)

    for star in stars:
        pygame.draw.rect(WIN, "white", star)

    pygame.display.update()

def main():
    run = True

    player = Player()

    #player = pygame.Rect(200, HEIGHT - PLAYER_HEIGHT, PLAYER_WIDTH, PLAYER_HEIGHT)

    clock = pygame.time.Clock()

    start_time = time.time()
    elapsed_time = 0

#    star_add_increment = 2000
#    star_count = 0

    stars = []
    hit = False

    while run:
    #    star_count += clock.tick(60)
        elapsed_time = time.time() - start_time

    #    if star_count > star_add_increment:
    #        for _ in range(5):
    #            star_x = random.randint(0, WIDTH - STAR_WIDTH)
    #            star = pygame.Rect(star_x, -STAR_HEIGHT, STAR_WIDTH, STAR_HEIGHT)
    #            stars.append(star)

    #        star_add_increment = max(200, star_add_increment - 50)
    #        star_count = 0

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False
                break

    #    keys  = pygame.key.get_pressed()
    #    if keys[pygame.K_LEFT] and player.x - PLAYER_VEL >= 0:
    #        player.x -= PLAYER_VEL
    #    if keys[pygame.K_RIGHT] and player.x + PLAYER_VEL + player.width <= WIDTH:
    #        player.x += PLAYER_VEL

    #    for star in stars[:]:
    #        star.y += STAR_VEL
    #        if star.y > HEIGHT:
    #            stars.remove(star)
    #        elif star.y + star.height >= player.y and star.colliderect(player):
    #            stars.remove(star)
    #            hit = True
    #            break

    #    if hit:
    #        lost_text = FONT.render("You Lost!", 1, "white")
    #        WIN.blit(lost_text, (WIDTH/2 - lost_text.get_width()/2, HEIGHT/2 - lost_text.get_height()/2))
    #        pygame.display.update()
    #        pygame.time.delay(4000)
    #        break

        draw(player, elapsed_time, stars)

    pygame.quit()

#if __name__ == "__main__":
 #   main()

There’s no error, just seems like it don’t want read the import Pygame

When you import pygame, pygame prints the text you see in your screenshot. This is expected behavior, and shows that pygame is in fact imported correctly.

It sounds like you expected something else to happen. If so, what?

Yup, Before updating Python3 it was opening a window, background, and player. (it was working correctly), but it didn’t get import player in Player because of the older Python --v.
So I update python3/pip3 and pygame, but now it show me this “contribute message” :confused: hehe

If the code you posted is the contents of main.py, running it with python main.py will not do anything beyond printing that message, because you never call the main function.

Updating Python would not have the effect you describe. Something else in your code or your environment has changed.

Notice the commented out if __name__ == '__main__' at the end of the code? Maybe that changed?

1 Like

OMG! Stupid error from me :joy: thank you very much guys! :raised_hands:t4:

i want install verjn 3.12.2