I have two images for the background a button, One of the images is the default image of the button, I want to change the background image of button, when I click it. This is my code:
and *.kv is:
Here is an example. I called the button SlideButton. It is created by adding ToggleButtonBehavior to an Image.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.behaviors import ToggleButtonBehavior
from kivy.uix.image import Image
kv = """
<SlideButton>:
allow_stretch: True # you can make this False if you do not want the button to scale with widget size
source: 'off.png'
on_state:
self.source = {'normal': 'off.png', 'down': 'on.png'}[self.state]
FloatLayout:
SlideButton:
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
size_hint: None, None
size: 200, 100
"""
class SlideButton(ToggleButtonBehavior, Image):
pass
class AMCustomToggle(App):
def build(self):
return Builder.load_string(kv)
AMCustomToggle().run()
--
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/80831568-d7a1-4123-866c-4f1a64be7575n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/60e5daf8.1c69fb81.1da20.59e2SMTPIN_ADDED_MISSING%40gmr-mx.google.com.