13

While running my program the icon I configured with pygame.display.set_icon(icon) displays only in the window. In the taskbar the default python icon remains the same.

Is there a way to change that?

Source:

import pygame
from pygame.locals import *
import sys, os
import time

pygame.init()


# Load Images
try:
    bg = os.getcwd() + '\\images\\background.png'
    background = pygame.image.load(bg).convert()
except:
    print 'Error: Could not find background.png'

try:
    logo = os.getcwd() + '\\images\\logo.png'
    c_logo = pygame.image.load(logo).convert()
except:
    print 'Error: Could not find logo.png'

try:
    about_dialog_infile = os.getcwd() + '\\images\\about_dialog[alpha].png'
    about_dialog = pygame.image.load(about_dialog_infile).convert_alpha()
except:
    pass

i_icon = os.getcwd() + '\\images\\icon.png'
icon = pygame.image.load(i_icon)
pygame.display.set_icon(icon)
pygame.display.set_caption("Test program")
screenSize =(640,480)

screen = pygame.display.set_mode(screenSize,0,32)
pygame.display.set_caption('My Test Program')



while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            # sys.exit()
        if event.type == MOUSEBUTTONDOWN:
            check_click(about, event.pos)


screen.blit(background, (0,0))

pygame.display.update()
Zack
  • 4,177
  • 8
  • 34
  • 52
  • @lunaryorn - haha! Yeah.. Embarrassing, really... I've got the *right* part of the code wrapped up now.. – Zack May 04 '12 at 00:36
  • I don't see any change concerning the exceptions... –  May 04 '12 at 15:02
  • @lunaryorn -- I was referring to my local machine.. But code is now fixed here, too! – Zack May 04 '12 at 15:57
  • Specify a concrete exception type to catch in the `except` statement, i.e. `EnvironmentError` in your case. A blank `except` hides non-related errors, and even programming errors like a `NameError` due to a misspelled name. –  May 08 '12 at 19:02

3 Answers3

10

I finally figured it out.

As far as I can tell, the only way to actually set that icon in the taskbar is during packaging.

With pyinstaller for example, you would call python pyinstaller.py --icon=icon.ico Where icon is the icon you want displayed in the task bar.

Zack
  • 4,177
  • 8
  • 34
  • 52
  • You should have specified in your original question that you where using a pyinstaller packaged module. The answer would've likely come a lot sooner. – PenguinCoder May 03 '12 at 19:50
  • 2
    @PenguinCoder at the time of the original writing I wasn't using pyinstaller. I only realized today while trying package my program that the taskbar could be set in this manner. – Zack May 04 '12 at 00:34
7

You might want to see this. Essentially, when windows sets the taskbar icon, it uses a variety of clever algorithms to decide the icon to use. The reason for this is so that if you have multiple instances of an application (i.e. multiple python windows) they will be grouped. This generally means that a python application's icon is set to the icon of python.exeor pythonw.exe, depending on your file extension (.py or .pyw). There is, however, a workaround. Because the taskbar icon is set by App User Models rather than by the specific executable, it is possible to change your application's User Model using the ctypesmodule:

import ctypes
myappid = 'mycompany.myproduct.subproduct.version' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)

So it's really not so much of a pygame thing as a windows thing generally.

Community
  • 1
  • 1
-2

I think to set the Taskbar Icon you have to use set_caption.

pygame.display.set_caption("Title", get_image_file("icon.png"))

Note: Set caption does not set the window icon. Call both set_icon and set_caption to set both.

SuperPrograman
  • 1,814
  • 17
  • 24
  • I just tested this out, but didn't have much luck. I posted the source above. It takes the code, and produces no errors, but the same default icon still shows in the task bar. – Zack Apr 30 '12 at 18:52
  • @SuperPrograman I don't see how it can work: From the doc: http://www.pygame.org/docs/ref/display.html#pygame.display.set_caption set_caption can take a shorter text in the caption but no directly icon. – ThePhi Jul 12 '15 at 06:37