Created
May 15, 2015 19:36
-
-
Save kived/962bba95ba044a0c2c76 to your computer and use it in GitHub Desktop.
Kivy: DictProperty demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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