Skip to content

Instantly share code, notes, and snippets.

@kived
Created May 15, 2015 19:36
Show Gist options
  • Save kived/962bba95ba044a0c2c76 to your computer and use it in GitHub Desktop.
Save kived/962bba95ba044a0c2c76 to your computer and use it in GitHub Desktop.
Kivy: DictProperty demo
import kivy
kivy.require('1.9.0')
from kivy.app import App
from kivy.lang import Builder
from kivy.properties import DictProperty
## Creating the property in Python
#from kivy.uix.boxlayout import BoxLayout
#class TestBox(BoxLayout):
# data = DictProperty({'a': ''})
root = Builder.load_string('''
#TestBox:
BoxLayout:
## Creating the property in kv
data: {'a': ''}
Label:
text: 'None' if not root.data['a'] else root.data['a']
Button:
text: 'set foo'
on_release: root.data['a'] = 'foo'
Button:
text: 'set bar'
on_release: root.data['a'] = 'bar'
''')
class TestApp(App):
def build(self):
return root
if __name__ == '__main__':
TestApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment