Utopion
Utopion

Reputation: 1128

Kivy: Change height of the Spinner's dropdown list

I have a spinner, I adapt the height to be 30dp, but in the dropdown list, the different choices keep the default height, how can I access them to change their height ?

from kivy.lang import Builder
from kivymd.app import MDApp

KV = '''
BoxLayout:
    Spinner:
        size_hint_y: None
        height: "30dp"
        values: ["Apple","Orange","Banana"]
'''

class App(MDApp):
    def build(self):
        self.box = Builder.load_string(KV)

        return self.box

App().run()

Upvotes: 1

Views: 299

Answers (2)

Utopion
Utopion

Reputation: 1128

python file:

from kivy.lang import Builder
from kivy.app import App
from kivy.uix.label import Label

class MyFirstKivyApp(App):

    def build(self):
        return Builder.load_file("main.kv")

MyFirstKivyApp().run()

kv file:

#:import Factory kivy.factory.Factory

<MySpinnerOption@SpinnerOption>:
    size_hint_y: None
    height: "30dp"
 
<MyThing@BoxLayout>:
    Spinner:
        text: "First thing"
        values: ["First thing", "Second thing", "Third thing"]
        option_cls: Factory.get("MySpinnerOption")
        size_hint: None, None
        height: "30dp"

MyThing:

Upvotes: 1

Zayn Naz
Zayn Naz

Reputation: 60

You can refer to this link https://github.com/kivy/kivy/wiki/Styling-a-Spinner-and-SpinnerOption-in-KV

In the SpinnerOptions part, you can set height: 30 and I hope it will change...

Upvotes: 1

Related Questions