Adjust Slider backgound image on value

48 views
Skip to first unread message

Mart1

unread,
Nov 17, 2019, 10:31:25 AM11/17/19
to Kivy users support
Hi,
I want to adjust the background image of my slider on the value of it.
I managed to get a backgound on all of my slider but I don't know how to adjust it on the value of it and discover my background more and more according to this value.

Slider:
    id
: temperature
    value_track
: True
    value_track_color
: [1, 0, 0, 1]
    min
: 0
    max
: 16
    value
: 5
    step
: 1
    orientation
: 'horizontal'
    on_touch_up
: root.get_value()
    cursor_image
: os.getcwd()+'\\_cursor.png'
    background_horizontal
: os.getcwd()+'\\_gradient_temperature.png'


Some guys told me to take a look there but I don't have any idea where to begin :(

Elliot Garbus

unread,
Nov 17, 2019, 11:56:42 PM11/17/19
to kivy-...@googlegroups.com
Here are 2 ideas for changing the color of the value track color.
You could do something similar and have a number of background images that change based on the value of the slider, if you want to change the background image.
 
What is the visual effect you want to achieve?
 
 
BoxLayout:
    orientation: 'vertical'
    Slider:
        color_value: 5/16
        id: temperature
        value_track: True
        value_track_color: [self.color_value, 0, 0, 1]

        min: 0
        max: 16
        value: 5
        step: 1
        orientation: 'horizontal'
        on_value: self.color_value = self.value_normalized
       
    Slider:
        color_value: 5/16

        id: temperature
        value_track: True
        value_track_color: [1, 0, 0, 1]
        min: 0
        max: 16
        value: 5
        step: 1
        orientation: 'horizontal'
        on_value: 
            if 0 < self.value < 5: self.value_track_color = [1, 0, 0, 1]
            if 5 < self.value < 10: self.value_track_color = [1, 1, 0, 1]
            if self.value > 10:  self.value_track_color = [0, 1, 0, 1]

--
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/88d5d47d-074b-4153-862e-df3b81ed683e%40googlegroups.com.

 

Mart1

unread,
Nov 18, 2019, 6:13:07 PM11/18/19
to Kivy users support
Okay not bad at all. value_track_color isn't suppose to be in rgba format ? So why when i putthis below, I have yellow color ? I should have orange nah ??
self.value_track_color = [255, 51, 0, 1]


In my mind I want something like this :

value_3_want.PNG


value_11_want.PNG


value_15_actual.PNG



But actully I have this no matter the value :

value_3_actual.PNG

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

Elliot Garbus

unread,
Nov 18, 2019, 7:13:06 PM11/18/19
to kivy-...@googlegroups.com

self.value_track_color = [255, 51, 0, 1]

 

Color is expressed between 0 and 1.  You could express the values above as: [1, 51/255, 0, 1]

 

To create the effect your looking for I would suggest deriving a class from Spinner.  On the canvas create a rectangle to cover/uncover the background image based on the position of the slider.  Give it a try.  If you need help let me know.

 

 

 

From: Mart1
Sent: Monday, November 18, 2019 4:13 PM
To: Kivy users support
Subject: Re: [kivy-users] Adjust Slider backgound image on value

 

Okay not bad at all. value_track_color isn't suppose to be in rgba format ? So why when i putthis below, I have yellow color ? I should have orange nah ??

self.value_track_color = [255, 51, 0, 1]

 

 

In my mind I want something like this :

 

 

 

 

But actully I have this no matter the value :

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/20279b6e-989b-4c0a-a95a-909717767101%40googlegroups.com.

 

Elliot Garbus

unread,
Nov 18, 2019, 9:56:42 PM11/18/19
to kivy-...@googlegroups.com

I had some free time… here you go.  Add your background gradient this should get you most of the way there.

The canvas is used to draw a black rectangle that matches the background, and covers the ‘track’

 

from kivy.app import App
from kivy.lang.builder import Builder

kv =
'''
<GradientSlider@Slider>
    canvas:
        Color:
            rgba: (0, 0, 0, 1)
        Rectangle:
            pos: self.value_pos[0] + self.cursor_size[0] / 2 - dp(1.25), self.pos[1]
            size: self.size
    
BoxLayout:
    orientation: 'vertical'
    GradientSlider:
        min: 0
        max: 100
        value: 50
        # add your background color and value_track_color here
    Slider:
        id:s3
        min: 0
        max: 100

        value_track: True
        value_track_color: [1, 0, 0, 1] 
    Label:
        text: str(s3.value_pos)

'''


class GradientSliderApp(App):
   
def build(self):
       
return Builder.load_string(kv)


if __name__ == '__main__':
    GradientSliderApp().run()
1A22263B1D844D97AA570BA7464AF0C6.png
01AD69E99AB44B7D856F76224B21B0D5.png
BA507780AA0B40FC89BC868E6E02F7E5.png
CC22D5A08CE444C7A5E963431B588687.png

Mart1

unread,
Nov 19, 2019, 6:49:18 AM11/19/19
to Kivy users support
Awesome ! Thanks mate !

--
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.

Mart1

unread,
Nov 19, 2019, 7:26:53 AM11/19/19
to Kivy users support
Still get a little question about it, how can I put the cursor image upper the black canvas ?
To be clear have this :

Cursor_want.PNG

Instead of this :

Cursor_actual.PNG


Of course if I put
-sp(32)
here:
<GradientSlider@Slider>

    canvas:
        Color:
            rgba: (0, 0, 0, 1)
        Rectangle:
            pos: self.value_pos[0] + self.cursor_size[0] / 2 - dp(1.25) - sp(32) , self.pos[1]
            size: self.size

Half of my cursor will be hide so...

Elliot Garbus

unread,
Nov 19, 2019, 8:14:15 AM11/19/19
to kivy-...@googlegroups.com

The simplest thing to do might be to color the background of the right side of your cursor black, rather than transparent.

 

From: Mart1
Sent: Tuesday, November 19, 2019 5:27 AM
To: Kivy users support
Subject: Re: [kivy-users] Adjust Slider backgound image on value

 

Still get a little question about it, how can I put the cursor image upper the black canvas ?

To be clear have this :

Instead of this :

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/e6669f33-29d9-4075-a820-278e5d28f70f%40googlegroups.com.

 

Mart1

unread,
Nov 19, 2019, 9:56:57 AM11/19/19
to Kivy users support
My bad didn't think about this lol. Thank you so much for all of your help !
Reply all
Reply to author
Forward
0 new messages