Change language

Python | Slider widget using .kv file

| |

Slider:
To work with the slider, you first need to import the module, which consists of all functions, functions of the slider, i.e.

  Module:  kivy.uix.slider 

Basic approach to follow when creating Slider —

 1) import kivy 2) import kivyApp 3) import BoxLayout 4) set minimum version (optional) 5) Extend the class 6) set up .kv file (name same as the Slider.kv) 7) Run an instance of the class 

Below is the code that implements slider with .kv file:

# main.py slider file

  
# Your application base class inherits from the application class.
# app: always refers to an instance of your application

from kivy.app import App

 
# BoxLayout places children in a vertical or horizontal border.
# or help put the kids in the right place.

from kivy.uix.boxlayout import BoxLayout 

 

 
# create the root widget used in the .kv file

class SliderWidget (BoxLayout):

pass

 
# class where the name of the .kv file should be called Slider.kv.
# or create an application class

class Slider (App):

def build ( self ):

# return a SliderWidget instance

return SliderWidget ()

 
# run application

if __ name__ = = ’__main__’ :

Slider (). run ()

Now file Slider.kv : file Slider.kv

"SliderWidget & gt ;:

 

# create a slider

Slider:

 

# giving the slider orientation

orientation: "vertical"

min : 0   # minimum Slider value

max : 100 # maximum Slider value

value: 0   # initial Slider value

 

# when the slider is moved to increase the value

on_value: label1.text = str ( int ( self . value))

 

# Add shortcut

  Label:

  id : label1

font_size: "30sp"

text: "0"

color: 1 , 0 , 0 , 1

 

Slider:

orientation: "horizontal"

min : 0

max : 100

value: 30

  on_value: label2.text = str ( int ( self . value))

 

 

Label:

  id : label2

  font_size: "30sp"

text: "30"

color: 0 , 0 , 1 , 1

Output:

For a slider without a .kv file, see — Python | Slider widget in Kiwi

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method