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

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically