0
1

More than 3 years have passed since last update.

KivyのUI要素のshow/hide

Last updated at Posted at 2019-12-21

main.py


#-*- coding: utf-8 -*-

from kivy.app import App
from kivy.uix.widget import Widget

from kivy.properties import NumericProperty 

class TestWidget(Widget):
    testTextInput2_Opacity = NumericProperty()
    testTextInput2_size_hint_y = NumericProperty()
    show_hide = 0

    def __init__(self, **kwargs):
        super(TestWidget, self).__init__(**kwargs)
        self.testTextInput2_Opacity = 1
        self.testTextInput2_size_hint_y = 0.2

    def buttonClicked(self):
        if self.show_hide == 0:
            self.ids.box.remove_widget(self.ids.testTextInput2)
            self.ids.box.add_widget(self.ids.testTextInput2, 0)
            self.testTextInput2_Opacity = 0
            self.show_hide = 1
        else:
            self.ids.box.remove_widget(self.ids.testTextInput3)
            self.ids.box.add_widget(self.ids.testTextInput3, 0)
            self.testTextInput2_Opacity = 1
            self.show_hide = 0

class TestApp(App):
    def __init__(self, **kwargs):
        super(TestApp, self).__init__(**kwargs)

    def build(self):
        return TestWidget()

if __name__ == '__main__':
    TestApp().run()

test.kv


#-*- coding: utf-8 -*-

from kivy.app import App
from kivy.uix.widget import Widget

from kivy.properties import NumericProperty 

class TestWidget(Widget):
    testTextInput2_Opacity = NumericProperty()
    testTextInput2_size_hint_y = NumericProperty()
    show_hide = 0

    def __init__(self, **kwargs):
        super(TestWidget, self).__init__(**kwargs)
        self.testTextInput2_Opacity = 1
        self.testTextInput2_size_hint_y = 0.2

    def buttonClicked(self):
        if self.show_hide == 0:
            self.ids.box.remove_widget(self.ids.testTextInput2)
            self.ids.box.add_widget(self.ids.testTextInput2, 0)
            self.testTextInput2_Opacity = 0
            self.show_hide = 1
        else:
            self.ids.box.remove_widget(self.ids.testTextInput3)
            self.ids.box.add_widget(self.ids.testTextInput3, 0)
            self.testTextInput2_Opacity = 1
            self.show_hide = 0

class TestApp(App):
    def __init__(self, **kwargs):
        super(TestApp, self).__init__(**kwargs)

    def build(self):
        return TestWidget()

if __name__ == '__main__':
    TestApp().run()

これで中間の要素をshow/hideできる
なんかあんまり使い方がしっくりこない
自分用メモ

0
1
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
0
1