LoginSignup
2
2

More than 5 years have passed since last update.

kv言語でSliderとTextInputの値を連動させる

Last updated at Posted at 2017-01-14

概要

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

結果

2017-01-14_10h30_52.png

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2