Kivy Course #7 – Introduction to Slider: Changing Background

In this example, a code changing background color of application according to slider position is written. In Kivy, color values are changing from 0 to 1 and as a result floating point numbers are used in order to give color value to canvas.

All red, green and blue components are made equal so you will see the versions of grey. The files are listed below. You may also find them in my

Github account.

Python file:

from import App
from kivy.uix.boxlayout import BoxLayout

class RootWidget(BoxLayout):

class SliderApp(App):
    def build(self):
        return RootWidget()

if __name__ == '__main__':
    App = SliderApp()

And the kivy file:

    orientation: 'vertical'
    slider_colors: [0.5, 0.5, 0.5]
            rgb: root.slider_colors
            pos: root.pos
            size: root.size
        min: 0
        max: 1
        value: 0.5
        on_value: color_label.text = "Renk " + \
        str(self.value); root.slider_colors = (self.value for i in xrange(3))
        id: color_label
        font_size: "50sp"
        text: "Renk 0.5"


comments powered by Disqus