R
R
Roma Kotolup2021-03-19 17:12:46
pygame
Roma Kotolup, 2021-03-19 17:12:46

How to change window icon on taskbar in pygame?

How to change window icon on taskbar in pygame?
Wrote a small pygame program:

game code

import pygame
import sys
import ctypes
 
FPS = 60
W = 700  # ширина экрана
H = 300  # высота экрана
WHITE = (255, 255, 255)
BLUE = (0, 70, 225)
 
sc = pygame.display.set_mode((W, H))
clock = pygame.time.Clock()
pygame.display.set_caption("circle!")
кув = pygame.image.load("C:\спрайти\кув.bmp")
pygame.display.set_icon(кув)
 
# координаты и радиус круга
x = W // 2
y = H // 2
r = 50
 
while 1:
    for i in pygame.event.get():
        if i.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
 
    sc.fill(WHITE)
    pygame.draw.circle(sc, BLUE, (x, y), r)
    pygame.display.update()
 
    keys = pygame.key.get_pressed()
 
    if keys[pygame.K_LEFT]:
        if x <= 47 and W == 700:
            pass
        else:
            x -= 3
    elif keys[pygame.K_RIGHT]:
        if x >= 647 and W == 700:
            pass
        else:
            x += 3
    if keys[pygame.K_DOWN]:
        print(y)
        if y >= 246 and H == 300:
            pass
        else:
            y += 3
    elif keys[pygame.K_UP]:
        print(y)
        if y <= 51 and H == 300:
            pass
        else:
            y -= 3
    clock.tick(FPS)


And he changed the icon only on the window and not on the taskbar.
I tried:
import ctypes
myappid = 'mycompany.myproduct.subproduct.version' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
But it only works with tkinter, not pygame.
This is what throws an error:
pygame.display.set_caption("Title", get_image_file("C:\спрайти\кув.bmp"))

Like this:
Traceback (most recent call last):
File "C:/Users/Oksana/Desktop/kuv.py", line 45, in
pygame.display.set_caption("Title", get_image_file("C:\sprite\kuv .bmp"))
NameError: name 'get_image_file' is not defined

Is there any other way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex F, 2021-03-19
@delvin-fil

import inspect, os.path
filename = inspect.getframeinfo(inspect.currentframe()).filename
path     = os.path.dirname(os.path.abspath(filename))
icon_surf = pygame.image.load(path + '/android.png')
    img = pygame.image.load(io.BytesIO(result))
    screen.blit(img, (0, 0))

This fragment.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question