概要
kv言語でSliderとTextInputの値を連動させる.
環境
- Python: 3.5.2
- Kivy: 1.9.1
python
main.py
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
class RootWidget(BoxLayout):
pass
class MainApp(App):
def build(self):
return RootWidget()
if __name__ == '__main__':
MainApp().run()
kv
main.kv
<RootWidget>:
orientation: 'vertical'
BoxLayout: # dummy
BoxLayout:
size_hint_y: None
height: 50.0
Slider:
id: testSlider
size_hint_x: 0.75
min: 0.0
max: 100.0
value: 20.0
# on_touch_move: testTextContent.text = '{:.0f}'.format(self.value) # sliderはイベント不要
TextInput:
id: testTextContent
size_hint_x: 0.25
text: '{:.0f}'.format(testSlider.value) # sliderの値を取得
multiline: False
on_text_validate: testSlider.value = int(self.text) # sliderに値を設定
BoxLayout: # dummy