The idea is pretty simple: I have a slider which affects the speed of a gif. However, I can't figure out how to trigger the image to get the updated "anim_delay" value from python (or for python to push it to kivy?).
The main file:
class BottomRightPart(BoxLayout):
imgdelay=-1
def OnFanSpeedSliderValueChange(self,slider,value):
if value == 0:
imgdelay = -1
elif value == 1:
imgdelay= 1
elif value == 2:
imgdelay = 0.6
elif value == 3:
imgdelay = 0.3
elif value == 4:
imgdelay = 0
The .kv code
<BottomRightPart>
BoxLayout:
Image:
id:FanImg
source: 'fan.gif'
anim_delay: root.imgdelay
Label:
text: str(int(FanSpeed.value))
Slider:
id:FanSpeed
min:0
max:4
step:1
on_value: root.OnFanSpeedSliderValueChange(*args)
Where's the missing link? Any pointers is appreciated!
You are missing self. Also set imgdelay to a NumericProperty.
Try this:
from kivy.properties import NumericProperty
class BottomRightPart(BoxLayout):
imgdelay = NumericProperty(-1)
def OnFanSpeedSliderValueChange(self,slider,value):
if value == 0:
self.imgdelay = -1
elif value == 1:
self.imgdelay= 1
elif value == 2:
self.imgdelay = 0.6
elif value == 3:
self.imgdelay = 0.3
elif value == 4:
self.imgdelay = 0
Personally I would create my method something like this:
def OnFanSpeedSliderValueChange(self,slider,value):
values = [-1, 1, 0.6, 0.3, 0]
self.imgdelay = values[int(value)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With