from kivy.app import App from kivy.lang import Builder from time import time from kivy.uix.label import Label from kivy.uix.boxlayout import BoxLayout import kivy.properties as kp from setproperty import SetProperty Builder.load_string(''' : orientation: 'vertical' text: '' BoxLayout: orientation: 'horizontal' ToggleButton: id: btn_add group: 'action' text: 'add' state: 'down' ToggleButton: group: 'action' text: 'delete' TextInput id: value Button: on_press: root.update_dict(btn_add.state == 'down', value.text) text: 'change set' Label: id: dictout text: root.text ''') class Foo(BoxLayout): text = kp.StringProperty() my_set = SetProperty() def on_my_set(self, wx, my_set): self.text = str(time()) + ' ' + str(my_set) def update_dict(self, add, value): if add: self.my_set.add(value) else: self.my_set.discard(value) class TestApp(App): def build(self): return Foo() if __name__ == '__main__': TestApp().run()