toufikovich
toufikovich

Reputation: 814

how to set the buttons size inside a spinner in kivy?

kindly need to know how to change or control the size of the special buttons inside a kivy spinner. note: my spinner is in the kv language and not in python and looks like this:

Spinner:
    id:some_id
    text:"some text"
    values:("1","2","3")
    size_hint:(None,None)
    size: root.width/4,root.height/12

Upvotes: 2

Views: 6510

Answers (1)

Nykakin
Nykakin

Reputation: 8747

Buttons inside of Spinner are of type passed to option_cls property. The default one is SpinnerOption class, which is actually a subclass of Button. You can change class passed to this property (it must have text property and on_release event) or modify SpinnerOption class globally:

from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.base import runTouchApp

Builder.load_string('''
<SpinnerOption>:
    size_hint: None, None
    size: 20, 20

<MyWidget>:
    Spinner:
        id:some_id
        text:"some text"
        values:("1","2","3")
        size_hint:(None,None)
        size: root.width/4,root.height/12
''')

class MyWidget(BoxLayout):pass

runTouchApp(MyWidget())

Using custom buttons:

from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.spinner import Spinner
from kivy.base import runTouchApp
from kivy.properties import ObjectProperty

Builder.load_string('''
<MyButton>:
    size_hint: None, None
    size: 20, 20

<MyWidget>:
    MySpinner:
        id:some_id
        text:"some text"
        values:("1","2","3")
        size_hint:(None,None)
        size: root.width/4,root.height/12
''')

class MyButton(Button):
    pass

class MySpinner(Spinner):
    option_cls = ObjectProperty(MyButton) # setting this property inside kv doesn't seem to work

class MyWidget(BoxLayout):
    pass    

runTouchApp(MyWidget())

Upvotes: 2

Related Questions