Dropdown menu

53 views
Skip to first unread message

Sid

unread,
Nov 20, 2021, 9:41:36 AM11/20/21
to Kivy users support
I was trying to implement drop-down menu in a project, but i was unable to do so, can anyone help me out?

I want to implement drop-down menu and i am using builder.load_string for returning.

Elliot Garbus

unread,
Nov 20, 2021, 9:44:53 AM11/20/21
to kivy-...@googlegroups.com

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.

 

Sid

unread,
Nov 20, 2021, 10:12:19 AM11/20/21
to Kivy users support
How can i add values dynamically?

Elliot Garbus

unread,
Nov 20, 2021, 10:23:36 AM11/20/21
to kivy-...@googlegroups.com
In kv, set the values attribute to a kv list property. 
Modifying the list will update the values. 

Let me know I’d that helps. If required I can create an example later today. 

Sent from my iPhone

On Nov 20, 2021, at 8:12 AM, Sid <saisiddh...@gmail.com> wrote:

How can i add values dynamically?

Sid

unread,
Nov 20, 2021, 10:25:14 AM11/20/21
to Kivy users support
An example will be great, thank you

Elliot Garbus

unread,
Nov 20, 2021, 6:23:06 PM11/20/21
to kivy-...@googlegroups.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()

Sid

unread,
Nov 20, 2021, 10:21:39 PM11/20/21
to Kivy users support
Thank you, I resolved my problem. thanks a lot
Reply all
Reply to author
Forward
0 new messages