请了解如何更改或控制 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
请了解如何更改或控制 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
内部的按钮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())