Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the icon on the window when I run my program in KIVY

Tags:

python

kivy

So I have read how to change the ICON on the window, however it seems to not be changing the icon when I run my program using Kivy and Python. Inside my python code there is something like this:

from kivy.core.window import Window
from kivy.config import Config
from kivy.app import App

Config.window_icon = "Desktop/X.jpg"

Lets say my picture is named X.jpg and has that right path. Is there another way to change that icon: The picture is attached to show what Icon I want to change.

I am using Python 2.7.x and Kivy 1.9.1 Thanks~enter image description here

like image 662
Omid CompSCI Avatar asked Nov 17 '16 22:11

Omid CompSCI


People also ask

How do you run a method on exit on KIVY app?

If you want your application to simply run things after the GUI has closed, the easiest and smallest approach would be to place any exit code after TestApp(). run() . run() creates a endless loop which also clears any event-data from within kivy so it doesn't hang.


3 Answers

The previous answer didn't work for me and I found another solution that did, so I wanted to share.

In build you can add:

self.icon = 'ico/path.ico'
like image 107
DaNNuN Avatar answered Oct 21 '22 12:10

DaNNuN


According to the documentation - Application

Icon of your application. The icon can be located in the same directory as your main file. You can set this as follows:

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



Changed in version 1.8.0: icon is now a StringProperty. Don’t set the icon in the class as previously stated in the documentation.

Note

For Kivy prior to 1.8.0, you need to set this as follows:

class MyApp(App):
    icon = 'customicon.png'

Recommended 256x256 or 1024x1024? for GNU/Linux and Mac OSX 32x32 for Windows7 or less. <= 256x256 for windows 8 256x256 does work (on Windows 8 at least), but is scaled down and doesn’t look as good as a 32x32 icon.

like image 35
Black Cat Avatar answered Oct 21 '22 10:10

Black Cat


Refering to:

https://kivy.org/docs/api-kivy.config.html

this should do it:

from kivy.config import Config
Config.set('kivy','window_icon','path/to/icon.ico')
like image 22
Jonas Avatar answered Oct 21 '22 10:10

Jonas