atmon3r
atmon3r

Reputation: 1980

Kivy clickable image that replaced a button

Looking for a way to use an image instead of a conventional button with kivy.
I try to use background_disabled_normal and background_disabled_down
This is my button part in my .kv file:

Button:
    on_press: root.do_action()
    background_disabled_normal: str(False)
    Image:
        source: 'icon.png'
        y: self.parent.y + self.parent.height - 250
        x: self.parent.x
        size: 250, 250
        allow_stretch: True

But not work

Upvotes: 3

Views: 6880

Answers (1)

inclement
inclement

Reputation: 29488

background_disabled_normal: str(False)

This should be a filepath to an image, not a string of a boolean. Also, this is the property for the background when the button's disabled property is True - are you sure you don't want background_normal?

There is another way to do this anyway that may suit you; the button stuff is abstracted as ButtonBehavior that may be combined with any widget.

from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.image import Image

class ImageButton(ButtonBehavior, Image):
    pass

This ImageButton will have all the properties of an image (you can set the source) and all the events of a button (on_press etc).

Upvotes: 12

Related Questions