Kivy Course #7 – Introduction to Slider: Changing Background
- July 9, 2015
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
Python file:
#-*-coding:utf-8-*-
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
class RootWidget(BoxLayout):
pass
class SliderApp(App):
def build(self):
return RootWidget()
if __name__ == '__main__':
App = SliderApp()
App.run()
And the kivy file:
<RootWidget>:
orientation: 'vertical'
slider_colors: [0.5, 0.5, 0.5]
canvas.before:
Color:
rgb: root.slider_colors
Rectangle:
pos: root.pos
size: root.size
Slider:
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))
Label:
id: color_label
font_size: "50sp"
text: "Renk 0.5"