Table Of Contents
Resources management¶
Resource management can be a pain if you have multiple paths and projects. Kivy offers 2 functions for searching for specific resources across a list of paths.
Resource lookup¶
When Kivy looks for a resource e.g. an image or a kv file, it searches through
a predetermined set of folders. You can modify this folder list using the
resource_add_path() and resource_remove_path() functions.
Customizing Kivy¶
These functions can also be helpful if you want to replace standard Kivy
resources with your own. For example, if you wish to customize or re-style
Kivy, you can force your style.kv or data/defaulttheme-0.png files to be
used in preference to the defaults simply by adding the path to your preferred
alternatives via the resource_add_path() method.
As almost all Kivy resources are looked up using the resource_find(), so
you can use this approach to add fonts and keyboard layouts and to replace
images and icons.
- kivy.resources.resource_add_path(path)[source]¶
Add a custom path to search in.
Changed in version 3.0.0: path may be a
os.PathLike(e.g.pathlib.Path) in addition to astr.
- kivy.resources.resource_find(filename, use_cache=False)[source]¶
Search for a resource in the list of paths. Use resource_add_path to add a custom path to the search. By default, results are cached for 60 seconds. This can be disabled using use_cache=False.
Changed in version 2.1.0: use_cache parameter added and made True by default.
Changed in version 3.0.0: Added support for @image_provider:providername(path) URI scheme.
Changed in version 3.0.0: filename may be a
os.PathLike(e.g.pathlib.Path) in addition to astr. It is coerced tostrbefore resolution so cache keys stay consistent.Changed in version 3.0.0: The result cache is keyed on a normalized form of filename, so different spellings of the same path (
'a/b.png'vs'a\b.png', redundant./..segments, case differences on case-insensitive platforms, andpathlib.Pathinputs) now share a single cache entry. URIs are keyed verbatim.
- kivy.resources.resource_remove_path(path)[source]¶
Remove a search path.
Added in version 1.0.8.
Changed in version 3.0.0: path may be a
os.PathLike(e.g.pathlib.Path) in addition to astr.