请知道如何更改或控制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
答案 0 :(得分:2)
Spinner
内的按钮是传递给option_cls
属性的类型。默认值为SpinnerOption
class,它实际上是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())