Here are the issues.
Image gets it’s image from source.
ButtonBehavior does not include image attributes. It does provide button state.
You can use state to dynamically select the image based on the state. This works for both ButtonBehavior and ToggleButtonBehavior.
I typically would do something like:
ImageButton:
source: {'normal': 'images/button-release.png', 'down': 'images/button-press.png'} [self.state]
keep_ratio: True
This line make look a little strange at first.
{'normal':'icons8-play-96.png', 'down': 'icons8-pause-96.png'} [self.state]
This is a dictionary. The state of the button, self.state, will be either 'normal’ or ‘down’.
The dictionary will provide one filename for ‘normal’, and another for ‘down’, providing a compact way of dynamically choosing the ‘normal’ and ‘down’ images based on state.
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/1e4ea3c1-b3d9-43b9-bd23-cf091b3c9e6a%40googlegroups.com.
For example, is it necessary for the ImageButton class, in this case, to be defined as a rule in the kv file?
Please excuse my ignorance. I am very new to Kivy and still learning.
Thanks in advance.
You can define the classes directly in kivy as ‘dynamic classes’ see: https://kivy.org/doc/stable/api-kivy.lang.html?highlight=lang#dynamic-classes
You do not need to kivy rule for things defined in Python. They can make it easier, Ideally you define the layout in kv, and the logic and data in python.
From: Shoumik Das
Sent: Tuesday, April 28, 2020 11:13 AM
To: Kivy users support
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/3c1eae6b-8fb8-4119-90eb-6cc500034425%40googlegroups.com.
You can define the classes directly in kivy as ‘dynamic classes’ see: https://kivy.org/doc/stable/api-kivy.lang.html?highlight=lang#dynamic-classes
You do not need to kivy rule for things defined in Python. They can make it easier, Ideally you define the layout in kv, and the logic and data in python.
From: Shoumik Das
Sent: Tuesday, April 28, 2020 11:13 AM
To: Kivy users support
Subject: RE: [kivy-users] Stretchable Image Button Keeping Aspect Ratio
Thanks for the suggestion, Elliott. I am wondering if it is mandatory for every class defined in Python to have a corresponding rule in Kivy.
For example, is it necessary for the ImageButton class, in this case, to be defined as a rule in the kv file?
Please excuse my ignorance. I am very new to Kivy and still learning.
Thanks in advance.
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.