kv 언어로 슬라이더와 TextInput의 값을 연결합니다

3870 단어 KivyPython

개요


kv 언어로 슬라이더와 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
    

    결실


    좋은 웹페이지 즐겨찾기