Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Kivy is a GUI tool that is platform-independent in Python. Kivy can be run on android, IOS, Linux, windows, etc. It is used to create the Android application, but this does not mean that we cannot use it on desktop applications. It also provides a slider widget for app development.
A slider is a widget used for selecting and setting a range of values from minimum values to maximum values. A slider can be placed either in a horizontal or vertical orientation. In the slider, the Normalized value means the minimum value is 0, and the maximum value is 1.
Procedure to create a slider
import slider
import kivy
import kivy app
import numeric property
Extend the class
Set minimum version
Import gridlayout(if needed)
Import label(if needed)
Run an instance of the class
Import numeric property
Example
Code 1:
In this example, we will create a slider widget using the main file and the .kv file. This example will result in a progress bar with its slider value.
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.slider import Slider
from kivy.uix.label import Label
from kivy.properties import NumericProperty
class WidgetContainer(GridLayout):
def __init__(self, **kwargs):
super(WidgetContainer, self).__init__(**kwargs)
# 2 columns in a grid layout
self.cols = 2
self.brightnessControl = Slider(min=0, max =100)
# 1st row - one label, one slider
self.add_widget(Label(text='brightness'))
self.add_widget(self.brightnessControl)
# 2nd row - one label for caption, one label for slider value
self.add_widget(Label(text='Slider Value'))
self.brightnessValue = Label(text='0')
self.add_widget(self.brightnessValue)
# On the slider object Attach a callback for the attribute named value
self.brightnessControl.bind(value=self.on_value)
def on_value(self, instance, brightness):
self.brightnessValue.text = "%d"%brightness
# The app class
class SliderExample(App):
def build(self):
widgetContainer = WidgetContainer()
return widgetContainer
# Run the app
if __name__ == '__main__':
SliderExample().run()
You can also try this code with Online Python Compiler
In this example, we will create a slider that will show its value. Below is the main python file in which a class extends from GridLayout; in Gridlayout, we have added two widgets labels and a slider.
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
class MyLayout(GridLayout):
pass
class SliderWindow(App):
def build(self):
return MyLayout()
if __name__ == "__main__":
window = SliderWindow()
window.run()
You can also try this code with Online Python Compiler
A slider widget looks like a scrollbar; it supports min/max values, horizontal and vertical orientation, and default values.
What is a Widget in Kivy?
A widget is a fundamental building block of the GUI interface in kivy. It receives events and reacts to them.
What is Builder in kivy?
It is a global instance used in widgets that you can use to load other kv files and the default.
How does a slider work?
A slider widget is a design that is used to present images and videos on your website. Slider works as a slideshow, showing one image or video at a time.
What is an Image slider?
A slider is a slideshow of images, videos, or texts that may automatically scroll and allow the visitors to scroll through them.
How do I use the slider widget in WordPress?
1. Activate the smart slider 3 plugin through the ‘plugins’ menu in WordPress.
2. Create a new slider: click on the slider menu and then you can add videos and images as slides and you can customize your slides with layers.
Conclusion
In this article, we have extensively discussed the slider widget using the .kv file. We started with a brief introduction to kivy, and widgets in kivy, then slider widgets using .kv with the help of examples.