change the label text by touching an image

13 views
Skip to first unread message

husam alkdary

unread,
Mar 28, 2020, 4:59:27 PM3/28/20
to Kivy users support
I create a page that have two images and one label 
and I want to change the label text by touch the image 
every image has a name so I want to display the name of the image on the label when it touch
I tried this but I only get the first image name when I touch any image even the other one ???
So what should I change to make my idea ??

FloatLayout:

 
Image:
 size_hint
: .5,.6
 pos_hint
: {'x': 0, 'y':.4}
 allow_stretch
: True
 keep_ratio
:False
 on_touch_down
: result.text = 'image1'
 source
: "images/image1.png"


FloatLayout:
 
Image:
 size_hint
: 0.5,.6
 pos_hint
: {'x': 0.5, 'y':.4}
 allow_stretch
: True
 keep_ratio
:False
 on_touch_down
:result.text = 'image2'
 source
: "images/image2.png"

BoxLayout:
 size_hint
: 1,.1
 pos_hint
: {'x': 0, 'y':.3}
 
Label:
 text
: 'your choose is '
 
 id
: result

Elliot Garbus

unread,
Mar 28, 2020, 5:38:33 PM3/28/20
to kivy-...@googlegroups.com

Do not use on_touch_down. 

Create an image that uses ButtonBehavior, and use on_release

 

See the example of the IconButton: https://kivy.org/doc/stable/api-kivy.uix.behaviors.html?highlight=iconbutton#adding-behaviors

--
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/126e46b9-4b1e-44a7-af2f-02a6c95aa7e1%40googlegroups.com.

 

husam alkdary

unread,
Mar 30, 2020, 2:43:26 PM3/30/20
to Kivy users support
I tried what you told me but I'm getting error

this's my root widget

class Image_example(FloatLayout,ButtonBehavior):
pass

in my kv file

Image_example:


FloatLayout:
Image:
size_hint: .5,.6
pos_hint: {'x': 0, 'y':.4}
            allow_stretch: True     
            keep_ratio:False
            on_release:R.text= 'image1'

source: "images/image1.png"


FloatLayout:
Image:
size_hint: 0.5,.6
pos_hint: {'x': 0.5, 'y':.4}
allow_stretch: True
keep_ratio:False
            on_release:R.text= 'image2'

source: "images/image2.png"

BoxLayout:
size_hint: 1,.1
pos_hint: {'x': 0, 'y':.3}
Label:
            text: ''
id: R
 the error I get

AttributeError: release

as I told you I want to change the label text by touching the images

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Elliot Garbus

unread,
Mar 30, 2020, 3:00:24 PM3/30/20
to kivy-...@googlegroups.com
Go back to the docs and look at the IconImage example. 

It should be
class ImageExample(ButtonBehavior, Image):
   pass

Then put ImageExample where you have Image in your kv 

Sent from my iPhone

On Mar 30, 2020, at 11:43 AM, husam alkdary <husamal...@gmail.com> wrote:


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/7c254c9e-7aa8-43c6-9918-535676a01c7b%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages