How to Create Slider in Python Kivy

This is our seventh article on Kivy , in this article we are going to learn How to Create Slider in Python Kivy. the Slider widget looks like a scrollbar. It supports horizontal and vertical orientations, min/max values and a default value.

 

 

 

Kivy Crash Course Articles

1: Kivy Crash Course Introduction & Installation

2: Introduction to Kv Design Language 

3: Kivy Button with Callbacks

4: Kivy Layout Management 

5: How to Create CheckBox in Kivy

6: Kivy Image And AsyncImage Example

 

 

 

 

Also you can watch the complete video for this article

 

 

 

So there are two ways that you can create slider in kivy, the first way is that you can create 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.

 

 

So now this is the code for creating of slider in kivy.

 

So now this is just a basic and simple slider, now let’s extend this and make it a little complex, also we are going to bind events for this slider.

 

 

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.

 

 

And in our main app class, we have just returned our GridLayout class.

 

If  you run the code this will be the result

 

Kivy Slider Example
Kivy Slider Example

 

 

 

So now let’s create the slider using the kivy file, so first of all this is my python code. in this code basically i have just created a new class that extends from the GridLayout class and i have returned that class in my main app class.

 

 

 

Now this is our .kv file, and i have name the file sliderwindow.kv, make sure that this name should be similar to the main app class name, in my case it is SliderWindow class.

 

 

 

If you run the code, this will be the result

How to Create Slider in Python Kivy
How to Create Slider in Python Kivy

Subscribe and Get Free Video Courses & Articles in your Email

 

Share via
Copy link
Powered by Social Snap
×