Taskbar Icon on Windows 7

161 views
Skip to first unread message

Elliot Garbus

unread,
Nov 17, 2018, 12:01:20 AM11/17/18
to Kivy users support
I have reduced my issue to this small example below.  When I run this app on Win7, I get the correct icon on in the corner of the window, but not on the taskbar.
How do I get the correct icon on the taskbar?  In the image below, the icon on the window in the green circle is correct, the icon in the red circle on the taskbar is not correct.

Also note in the code, I have tried a number of image formats and resolutions.  As a side note a 250x250 png file shows up on the top-bar of the window only occasionally.
I have attached the code, the icon file(*.ico) and a 32x32 png file.

Thanks in advance (and Kivy is AWESOME!)
-Elliot 



from kivy.app import App
from kivy.uix.label import Label


class MyApp(App):
title = 'Test Case for icons Windows7'

def build(self):
# SELECT ANY ONE of the following test conditions...
self.icon = 'SY300logo_icon.ico' # Windows Icon, multi reso, works in window corner, not on taskbar
#self.icon = 'SY300logo.png' # png 250x250, image on window on some runs - very strange, not on taskbar
#self.icon = 'SY300logo128.png' # png 128x128, works on window, not on taskbar
#self.icon = 'SY300logo64.png' # png 64x64, works on window, not on taskbar
#self.icon = 'SY300logo32.png' # png 32x32, works on window, not on taskbar
#self.icon = 'SY300logo.jpg' #jpg 250x250, does not work
#self.icon = 'SY300logo64.gif' # gif works on window, not on taskbar

return Label(text='Wrong Logo on Task bar for Win7?')


if __name__ == '__main__':
MyApp().run()

wrongicon.JPG


icontest.py
sy300logo_icon.ico
SY300logo64.png

ZenCODE

unread,
Nov 17, 2018, 8:07:22 AM11/17/18
to Kivy users support
Try

    from kivy.core.window import Window
   
Window.set_icon("my_icon.png")


Elliot Garbus

unread,
Nov 17, 2018, 11:48:55 AM11/17/18
to Kivy users support
@ZenCODE Thanks for your reply.  Unfortunately, your suggestion results in the same behavior.  
Could this be a bug in SDL2?

Elliot Garbus

unread,
Nov 17, 2018, 6:52:12 PM11/17/18
to Kivy users support
Same problem exists on Windows 10, even running the examples that come with Kivy.

ZenCODE

unread,
Nov 18, 2018, 2:57:47 PM11/18/18
to Kivy users support
Yes. Kivy uses the SDL implementation here, so it would seem it is still something that needs to be addressed in those libs. That would be the best place to follow up. Alternatively, you could look into using the pywin32api and do that yourself. That will almost certainly mean preparing windows friendly icons (they are normally a quite specific format) and calling the respective API's to set them as the window icon.


Good luck

Elliot Garbus

unread,
Nov 18, 2018, 3:42:24 PM11/18/18
to Kivy users support
The stack overflow answer looks promising.  I'll give it a try.  
Thanks!!!

Elliot Garbus

unread,
Nov 19, 2018, 12:13:02 AM11/19/18
to Kivy users support
This turned into a more complex journey than I anticipated - but I now have it working.
The code:

from kivy.config import Config  # In my 'real' app, if this is not at the top it doesn't work
Config.set('graphics', 'width', 1725)
Config.set('graphics', 'height', 710)
Config.set('graphics', 'position', 'custom')
Config.set('graphics', 'top', 285)
Config.set('graphics', 'left', 185)
import kivy.utils
import ctypes
if kivy.utils.platform == 'win': # This code was also location dependent in my 'real' app
myappid = 'icontest.py' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
from kivy.app import App
#from kivy.core.window import Window - if kivy.core.window imported taskbar icon is wrong.
from kivy.uix.label import Label


class MyApp(App):
title = 'Test Case for icons Windows7'
    #Window.size = (1725, 710) # These require kivy.core.window, replaced with config calls
#Window.top = 285
#Window.left = 185

def build(self):
self.icon = 'SY300logo64.png'
return Label(text='Correct Logo on Taskbar for Win7')



if __name__ == '__main__':
MyApp().run()

Additional Comments:
The line 'from kivy.core.window import Window' caused the taskbar to revert the python default.  There could be some order dependent interaction here.  I used config.set() to replace the need for the Window.size() and position calls.  The call to ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid) also worked when moved to the top of the file.  It was not working properly in the build(), or when execution just prior to the call to run.

This feels a little hacked.  I'm open to any suggestions to make this more robust.
There is an issue in Kivy on Windows.  In the demo apps and in simple tests the default Kivy icon is not showing up on the taskbar.  Instead the logo for python is showing up.

Thanks again to @ZenCODE the stackoverflow example was very helpful.
Reply all
Reply to author
Forward
0 new messages