Kivy Tutorials
About Lesson

In this Kivy Tutorial we are going to talk about Kivy Slider, the Slider widget looks like a scrollbar. It supports horizontal and vertical orientations, min/max values and a default value.

 

 

There are two ways that you can create slider in kivy, the first way is that you can create kivy slider using the kivy.uix.slider module, and the second way is using the kivy design language, so first let’s just do the first way. also iam going to show you how to create callbacks for the kivy slider.

 

 

This is the code for creating slider in kivy

 

 

In the above code we have just created a simple slider, if you run the code this will be the result.

Kivy Tutorial - Kivy Slider
Kivy Tutorial – Kivy Slider

 

 

Now i want to add callback for the slider, i want by changing the slider the value of my label should be changed.

 

 

OK in the above code, you can see that first we have created a class that extends from the GridLayout, also we have added our Slider with the Label in that class, also you can see that we have binded the event to the slider like this.

 

 

 

And this is the method that we have binded with the slider. basically it is just a simple method and we are going to change the value of the label when the slider changes.

 

 

Run the complete code and this is the result.

Kivy Slider
Kivy Slider

 

 

 

Creating Kivy Slider with KV Language

Now we want to create our Slider using Kivy Design Language, create a new Python file and add the following codes in the file. in this code our class extends from GridLayout, because we want to add our two widgets label and slider in the GridLayout. in our main class we just return our layour class.

 

 

 

This is our kv file, make sure that the file name should be the same as your main class, for example in here our main class is SliderWindow, and the file should be sliderwindow.kv.

 

 

 

Run the complete code and this is the result.

Kivy Tutorial - Kivy Slider
Kivy Tutorial – Kivy Slider
Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.
Exercise Files
No Attachment Found
No Attachment Found