community
community copied to clipboard
Window Application icon doesn't work
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.
This same issue repros for me in my own code. Same code runs fine on OSX.
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.
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...
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.
Interesting - I'm using a PNG (as per examples) but will try an ICO.
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.
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.
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.
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...
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
?
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.
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
Ah, thanks for that Unity pointer!
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.
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:
- *.ico are not supported, use *.png
- check your path, add
assert self.get_application_icon() != ""
if unsure
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.
Is there a fix for this?
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
Ah, yes it is. I'll have to run it through internet archive later.
@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
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
how is this still broken
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