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.
???????? Kivy Tutorial – Learn Kivy with Examples.
Dropdown list
A drop-down list can be used with custom widgets. It allows you to display a list of widgets under a displayed widget. Unlike other toolkits, the list of widgets can contain any type of widget: simple buttons, images etc. The positioning of the drop-down list is fully automatic: we will always try to place the dropdown list in a way that the user can select an item in the list. Some important points to keep in mind while making a drop-down list:
- When adding widgets, we need to specify the height manually (disabling the size_hint_y) so the dropdown can calculate the area it needs.
- All the buttons within the dropdown list will trigger the dropdown DropDown.select() method. After being called, the main button text will display the selection of the dropdown.
To work with this widget you must have to import: from kivy.uix.dropdown import DropDown
Basic Approach:
1) import kivy
2) import kivy App
3) import dropdown list
4) import button
5) set minimum version(optional)
6) import runTouchApp
7) Create dropdown
8) create runtouchApp method
which takes widget as an argument
to run the App
Implementation of the Approach –
Python3
import kivy
from kivy.app import App
kivy.require( '1.9.0' )
from kivy.uix.dropdown import DropDown
from kivy.uix.button import Button
from kivy.base import runTouchApp
dropdown = DropDown()
for index in range ( 10 ):
btn = Button(text = 'Value % d' % index, size_hint_y = None , height = 40 )
btn.bind(on_release = lambda btn: dropdown.select(btn.text))
dropdown.add_widget(btn)
mainbutton = Button(text = 'Hello' , size_hint = ( None , None ), pos = ( 350 , 300 ))
mainbutton.bind(on_release = dropdown. open )
dropdown.bind(on_select = lambda instance, x: setattr (mainbutton, 'text' , x))
runTouchApp(mainbutton)
|
Output: Image 1:
Image 2: 