If you are trying to do a simple drop down use the Spinner. https://kivy.org/doc/master/api-kivy.uix.spinner.html?highlight=spinner#module-kivy.uix.spinner The drop down is for making more customized drop down widgets.
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/2ff8d3df-2387-42b8-b781-650b6c770009n%40googlegroups.com.
On Nov 20, 2021, at 8:12 AM, Sid <saisiddh...@gmail.com> wrote:
How can i add values dynamically?
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/751b2da0-a7b9-4949-bbd6-e6826a09547en%40googlegroups.com.
Here is an example with 2 spinners. The top spinner, FoodSpinner, uses a kivy ListProperty to hold the values.
The bottom part of the example manipulates the values list of the spinner directly.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.spinner import Spinner
from kivy.properties import ListProperty
kv = """
BoxLayout:
orientation: 'vertical'
RelativeLayout:
FoodSpinner:
id: food_spinner
size_hint: None, None
size: 200, 48
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
values: self.items
text_autoupdate: True
BoxLayout:
size_hint_y: None
height: 48
Button:
text: 'Fruits'
on_release: food_spinner.set_fruits()
Button:
text: 'Vegetables'
on_release: food_spinner.set_veg()
RelativeLayout:
Spinner:
id: spinner
size_hint: None, None
size: 200, 48
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
text_autoupdate: True
values: [str(x) for x in range(1, 20, 2)]
BoxLayout:
size_hint_y: None
height: 48
Button:
text: 'Odd'
on_release: spinner.values = [str(x) for x in range(1, 20, 2)]
Button:
text: 'Even'
on_release: spinner.values = [str(x) for x in range(0, 20, 2)]
"""
class FoodSpinner(Spinner):
vegetables = ['Broccoli', 'String Beans', 'Peppers']
fruits = ['Apple', 'Banana', 'Orange', 'Cherry']
items = ListProperty(fruits)
def set_fruits(self):
self.items = self.fruits
def set_veg(self):
self.items = self.vegetables
class DynaSpinnersApp(App):
def build(self):
return Builder.load_string(kv)
DynaSpinnersApp().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/170a16bc-ab9d-46b8-a1af-5de761b5e9d2n%40googlegroups.com.