Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

kivy dropdown list

from kivy.uix.dropdown import DropDown
from kivy.uix.button import Button
from kivy.base import runTouchApp

# create a dropdown with 10 buttons
dropdown = DropDown()
for index in range(10):
    # When adding widgets, we need to specify the height manually
    # (disabling the size_hint_y) so the dropdown can calculate
    # the area it needs.

    btn = Button(text='Value %d' % index, size_hint_y=None, height=44)

    # for each button, attach a callback that will call the select() method
    # on the dropdown. We'll pass the text of the button as the data of the
    # selection.
    btn.bind(on_release=lambda btn: dropdown.select(btn.text))

    # then add the button inside the dropdown
    dropdown.add_widget(btn)

# create a big main button
mainbutton = Button(text='Hello', size_hint=(None, None))

# show the dropdown menu when the main button is released
# note: all the bind() calls pass the instance of the caller (here, the
# mainbutton instance) as the first argument of the callback (here,
# dropdown.open.).
mainbutton.bind(on_release=dropdown.open)

# one last thing, listen for the selection in the dropdown list and
# assign the data to the button text.
dropdown.bind(on_select=lambda instance, x: setattr(mainbutton, 'text', x))

runTouchApp(mainbutton)
Comment

PREVIOUS NEXT
Code Example
Python :: how to reference variable in another file python 
Python :: formula of factorial 
Python :: python set with counts 
Python :: HUNGRY CHEF codechef 
Python :: variable in regex python 
Python :: how to change character in string python 
Python :: virtualenv 
Python :: how to eliminate duplicate values in list python 
Python :: floating point python 
Python :: python run code at the same time 
Python :: how to combine strings python 
Python :: how to get what type of file a file is in python 
Python :: how to check if a variable in python is a specific data type 
Python :: reversed python 
Python :: django template add numbers 
Python :: gaussian filter 
Python :: create forms in django 
Python :: list to csv python 
Python :: reading a file line by line using a generator 
Python :: classification cross validation 
Python :: ValueError: query data dimension must match training data dimension 
Python :: python loop shorthand 
Python :: how to rename files python 
Python :: How to import HTML code into python with selenium webdriver 
Python :: run a python script from another python script on a raspberry pi 
Python :: python how to align text writen to a file 
Python :: Shapes (None, 1) and (None, 5) are incompatible 
Python :: read pickle file 
Python :: Splitting strings in Python without split() 
Python :: plt tickpad 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =