Why does pygame set the title icon to the python runtime icon?

Viewed 48

When I try to set a pygame window's icon to a png, it sets it to the python console icon. I'm very rusty from not doing pygame a lot, but this doesn't seem to happen to other people. I use pygame 2.1.2 and python 3.9.7, if it helps.

Here is the code to my program:

import pygame
from time import sleep as wait
from os.path import join as path
from random import choice
from pygame.locals import MOUSEBUTTONDOWN, KEYDOWN, BUTTON_LEFT, K_a, K_d, K_w, QUIT
from threading import Thread
image_start = "images"

pygame.init()

icon = pygame.image.load(path(image_start, "icon.png"))

win = pygame.display.set_mode(size=(1200, 800))
pygame.display.set_caption("8 Hours At Nova Willow's")
pygame.display.set_icon(icon)

nova_willow = pygame.image.load(path(image_start, "nova_willow.png"))
camera = pygame.image.load(path(image_start, "camera.png"))
camoverlay = pygame.image.load(path(image_start, "camoverlay.png"))
camoverlay.set_alpha(146)
static1 = pygame.image.load(path(image_start, "static1.png"))
static1.set_alpha(146)
static2 = pygame.image.load(path(image_start, "static2.png"))
static2.set_alpha(146)
static3 = pygame.image.load(path(image_start, "static3.png"))
static3.set_alpha(146)
x = 0
y = 0
static = [static1, static2, static3, static2, static3, static1]

#Note: KEYDOWN only activates at the beginning of a key press, Same for MOUSEBUTTONDOWN, just for the mouse

cameraon = False
while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            quit(0)
        if event.type == KEYDOWN:
            if event.key == K_w:
                cameraon = not cameraon
    # if floor(staticindex) == 
    staticChoice = choice(static)
    win.fill((0, 0, 0))
    if cameraon:
        win.blit(camera, (x, y))
        win.blit(staticChoice, (0, 0))
        win.blit(camoverlay, (0, 0))
    pygame.display.update()
    
    wait(0.01)

There are no errors in this, but the icon isn't what I want it to be.

1 Answers

I am not sure if this is because of your old version, but I don't think so. To set your caption you put pygame.display.set_caption("") but for your icon you put win.set_icon(icon)

In my current project (I am on 2.1.2), I use pygame.display.set_icon(icon) to set my icon instead.

This format matches your set_caption function so I think it might work, lmk!

Related