Python | Spinner widget in kivy
Kivy is a platform independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications.
Spinner widget :
To work with spinner you must have to import:
from kivy.uix.spinner import Spinner
Spinner is a widget that provides a quick way to select one value from a set. In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all the other available values from which the user can select a new one.
Like a combo box, a spinner object can have multiple values and one of the values can be selected.
A callback can be attached to the spinner object to receive notifications on selection of a value from the spinner object.
Basic Approach : 1) import kivy 2) import kivyApp 3) import Label 4) import Spinner 5) import Floatlayout 6) Set minimum version(optional) 7) create App class: 1) Create the spinner 2) Attach the labels to spinners 3) Attach a callback also 8) return Layout/widget/Class(according to requirement) 9) Run an instance of the class
Implementation of a simple spinner:
Now if we have to tell user every time which element in a list is selected, we will display a label just beside the spinner which tells about the selected label. Also, we will print the value, and text of spinner.
Below is the Implementation:
Below is the output in video to get better understanding:
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course