community icon indicating copy to clipboard operation
community copied to clipboard

Window Application icon doesn't work

Open WnP opened this issue 10 years ago • 23 comments

on windows platform with kivy 1.8.0 ‘portable package’, App.icon doesn't set the window icon, tested with the following code:

from kivy.app in App

class MyApp(App):
    def build(self):
        self.icon = 'myicon.png'

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

example from the kivy.App documentation

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

WnP avatar May 21 '14 14:05 WnP

This same issue repros for me in my own code. Same code runs fine on OSX.

pugwonk avatar Jun 11 '14 18:06 pugwonk

Are you sure that the app can find the icon? Try running app.get_application_icon() to see if it returns the path to the icon (if it found it), or an empty string (if it didn't find it). It works for me on windows, although admittedly, I'm running master.

matham avatar Jun 11 '14 20:06 matham

self.get_application_icon() returns the correct path to my icon. I wonder if it's provided in a resolution that Kivy doesn't support or something...

pugwonk avatar Jun 11 '14 21:06 pugwonk

I thought there were different files that could be used as icons on different platforms. But I cannot find any mention of this in the docs at the moment. What file type are you using? I'm using a ico file.

matham avatar Jun 12 '14 02:06 matham

Interesting - I'm using a PNG (as per examples) but will try an ICO.

pugwonk avatar Jun 12 '14 02:06 pugwonk

ICO file works great - thanks for the tip. I think this bug is still valid, though, as PNG works on OSX and the docs imply it is platform-independent.

pugwonk avatar Jun 12 '14 05:06 pugwonk

I definitely remember seeing a list somewhere saying which file types were supported for an icon on each platform, and that only ico was supported on Windows. But I cannot find it now.

matham avatar Jun 12 '14 05:06 matham

It mentions sizes here, but it is not accurate: https://github.com/kivy/kivy/blob/b72d1735a91b5cabad8343e8d63f84c840df1a96/kivy/app.py#L386

Relevant info for windows ico from https://github.com/kivy/kivy/commit/e0f59eb16602a5f0ada0af9a02db157a248dad9d: "You need to provide a .ico along the .png, and must contain at a 16x16 and 48x48 image."

We should list the needed sizes and extensions for every platform.

dessant avatar Nov 03 '15 18:11 dessant

Doesn't seem to work on Ubuntu 15.10, either, with the Unity desktop. Works with the xfce4 desktop on Ubuntu 16.04, though. Though I guess this is an SDL issue...

janssen avatar Apr 19 '16 23:04 janssen

Doesn't work here either (16.04 Unity).

@dessant If we provide a png and an ico file, which one will be referenced with self.icon?

CreamyCookie avatar May 13 '16 21:05 CreamyCookie

I just upgraded from Kivy 1.8.0 to 1.9.1 and there was a behavioural change on Windows. Yes, png works across OSX and Windows now, in fact, it is the other way: ico no longer works on Windows. But there is a caveat: OSX supports and requires 1024x1024 icons and kivy supports that on OSX, but on Windows the png cannot exceed 512x512 or it will not display.

cyberstudio10 avatar Sep 06 '16 04:09 cyberstudio10

Bug still present on Ubuntu 16.04 and Kivy 1.9.2.

One reason is because the icon doesn't appear on Ubuntu Unity is because that OS relies on .desktop files. On my blog, I describe a handy workaround:

~~http://www.indeliblebluepen.com/?p=1012~~

https://dev.to/codemouse92/icons-python-and-ubuntu

CodeMouse92 avatar Feb 18 '17 01:02 CodeMouse92

Ah, thanks for that Unity pointer!

janssen avatar Feb 21 '17 18:02 janssen

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 07 '17 03:10 stale[bot]

Problem persists in current version v1.10.1. What worked for me was setting an *.png image instead of an *.ico. It seems like there are two problems at work here:

  1. *.ico are not supported, use *.png
  2. check your path, add assert self.get_application_icon() != "" if unsure

ModischFabrications avatar Sep 28 '18 11:09 ModischFabrications

tried to track this down, and found at least two issues.

Firstly the App's .icon property usually gets bypassed with SDL2, since the first mention of

from kivy.core.window import Window

makes an instance of Window, and right in the create_window function sets the icon, long before your App class is even found.

This function sets it using

filename_icon = self.icon or Config.get('kivy', 'window_icon')

where self.icon is an empty StringProperty which you are unable to manipulate, since the code runs on module import.

Alright, so we set that property, right? Config.set("kivy", "window_icon",ICON)

This then sets the variable, as long as you keep your slashes and backslashes ok, else it ignores the set call completely.

The create window function then calls self.set_icon(filename_icon) which goes to self._win.set_window_icon(str(filename)) which is in a pyd file. At this point the file name is correct, but no icon appears. Not with ico files, nor with png, of whatever size.

sanderland avatar May 01 '20 23:05 sanderland

Is there a fix for this?

luckyowl20 avatar Jun 16 '20 05:06 luckyowl20

Bug still present on Ubuntu 16.04 and Kivy 1.9.2.

One reason is because the icon doesn't appear on Ubuntu Unity is because that OS relies on .desktop files. On my blog, I describe a handy workaround: http://www.indeliblebluepen.com/?p=1012

@CodeMouse92 this link is broken

maltfield avatar Sep 27 '20 15:09 maltfield

Ah, yes it is. I'll have to run it through internet archive later.

CodeMouse92 avatar Sep 27 '20 16:09 CodeMouse92

@maltfield Hm, it appears it wasn't archived, however, I DID republish it on DEV a while back! (I'd forgotten).

https://dev.to/codemouse92/icons-python-and-ubuntu

CodeMouse92 avatar Sep 28 '20 15:09 CodeMouse92

I encountered a similar issue and was able to come up with a workaround...

My problem was the .ico file would not load in the ActionPrevious icon, however it would load for the app icon. I added a .png to the project and now it loads fine: https://github.com/n2qzshce/ham-radio-sync/blob/1819c70019f9e42140b056b76b082bb0208454af/src/ui/app_window.py#L135

n2qzshce avatar Mar 26 '21 00:03 n2qzshce

how is this still broken

yukkidev avatar Apr 06 '22 03:04 yukkidev

how is this still broken

@yukkidev I was able to get this working in my project, you may be able to use it for a reference: https://github.com/n2qzshce/ham-radio-sync/blob/1819c70019f9e42140b056b76b082bb0208454af/src/ui/app_window.py#L135

n2qzshce avatar Apr 06 '22 16:04 n2qzshce