It's possible to make the canvas color changes according to another widget value like slider or switch or …..
--
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/fdca5c07-a447-44ee-aa2e-ebb4b10ff645%40googlegroups.com.
Yes. It’s quite easy.For example use a slider to set a kivy numeric property, put the property values in the color field of the canvas.
It's possible to make the canvas color changes according to another widget value like slider or switch or …..--
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.
Two examples below. Top examples create a class and explicitly declare NumericProperties.
The lower example creates kivy object properties in the kv file.
I prefer to use the NumericProperties directly.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import NumericProperty
kv = """
<ColorBox>:
orientation: 'vertical'
canvas:
Color:
rgb: root.red, root.green, root.blue
Rectangle:
size: self.size
pos: self.pos
Slider:
max: 100
value: 50
step: 1
on_value: root.red = self.value/100
Slider:
max: 100
value: 50
step: 1
on_value: root.green = self.value/100
Slider:
max: 100
value: 50
on_value: root.blue = self.value/100
ColorBox:
"""
class ColorBox(BoxLayout):
red = NumericProperty(.5)
green = NumericProperty(.5)
blue = NumericProperty(.5)
class ColorSlidersApp(App):
def build(self):
return Builder.load_string(kv)
ColorSlidersApp().run()
Here is how to do it declaring red, green and blue all in kivy.
from kivy.app import App
from kivy.lang import Builder
kv = """
BoxLayout:
orientation: 'vertical'
red: 0.5
green: 0.5
blue: 0.5
canvas:
Color:
rgb: root.red, root.green, root.blue
Rectangle:
size: self.size
pos: self.pos
Slider:
max: 100
value: 50
step: 1
on_value: root.red = self.value/100
Slider:
max: 100
value: 50
step: 1
on_value: root.green = self.value/100
Slider:
max: 100
value: 50
on_value: root.blue = self.value/100
"""
class ColorSlidersApp(App):
def build(self):
return Builder.load_string(kv)
ColorSlidersApp().run()
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/0e76cdc0-5461-45e9-bb13-43615e67ff2e%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/0e76cdc0-5461-45e9-bb13-43615e67ff2e%40googlegroups.com.
Any kivy property creates an associated event. The event is named on_property_name
If you create a property ‘question’ there will be an event created on_question. The event will fire with the value of question is changed.
In a slider value is the value of the slider, it is a kivy property, and so on_value fires when the value of the slider changes.
A switch uses active, there is an on_active event that fires when the switch state is changed.
Read about properties: https://kivy.org/doc/stable/api-kivy.properties.html?highlight=properties#observe-using-on-propname
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/7fd2884b-f032-4eea-8474-c4d9d52aec07%40googlegroups.com.
root.red
app.root.sm.ids.get_screen('screen name').ids.boxlayout_id.red
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/7fd2884b-f032-4eea-8474-c4d9d52aec07%40googlegroups.com.
Show the code. It all depends on how you put the pieces together.
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/63d3258c-c466-4cde-bc0e-da5bc3db246f%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/63d3258c-c466-4cde-bc0e-da5bc3db246f%40googlegroups.com.