2

请了解如何更改或控制 kivy 微调器内特殊按钮的大小。注意:我的微调器是 kv 语言而不是 python,看起来像这样:

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

1 回答 1

2

内部的按钮Spinner属于传递给option_cls属性的类型。默认的是SpinnerOptionclass,它实际上是Button. 您可以更改传递给此属性的类(它必须具有text属性和on_release事件)或SpinnerOption全局修改类:

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())

使用自定义按钮:

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())
于 2013-11-12T12:12:52.847 回答