In this video we’ll learn how to create Sliders for Kivy and Python.
Slider for Kivy are incredibly easy to create. You just define them in your .kv file, add a min and max value, then create an on_value function to do, whatever you want the slider to do.
In this video we’ll just output the value of the slider to the screen (numbers between 1 and 50). We’ll also increase the font size of our label to whatever our Slider value is.
Python Code: slider.py
GitHub Code: slider.py
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivy.lang import Builder
#from kivy.uix.slider import Slider
# Designate Our .kv design file
Builder.load_file('slider.kv')
class MyLayout(Widget):
def slide_it(self, *args):
#print(args[1])
self.slide_text.text = str(int(args[1]))
self.slide_text.font_size = str(int(args[1]) * 5)
class AwesomeApp(App):
def build(self):
return MyLayout()
if __name__ == '__main__':
AwesomeApp().run()
Kivy Design Code: slider.kv
GitHub Code: slider.kv
<MyLayout> slide_text: slider_label BoxLayout: orientation: "vertical" size: root.width, root.height Label: id: slider_label text: "Slide The Slider!" font_size: 32 Slider: min: 1 max: 50 step: 1 orientation: "horizontal" on_value: root.slide_it(*args)

Add comment