Skip to content

Instantly share code, notes, and snippets.

@AlbericC
Last active August 29, 2015 14:16
Show Gist options
  • Save AlbericC/8262cb6b7e9516d6c03a to your computer and use it in GitHub Desktop.
Save AlbericC/8262cb6b7e9516d6c03a to your computer and use it in GitHub Desktop.
Pass extra information to a kv-defined widget
from kivy.app import App
from kivy.lang import Builder
from kivy.factory import Factory
from kivy.uix.boxlayout import BoxLayout
kv = """
<Test>:
orientation: 'vertical'
Button:
text: 'Add a new button'
on_press: root.callback()
<MyButton@Button>:
amount: self.amount
text: self.text
on_press: print(self.amount)
"""
Builder.load_string(kv)
class Test(BoxLayout):
def __init__(self, *args, **kwargs):
super(Test, self).__init__(*args, **kwargs)
self.callback()
def callback(self):
self.add_widget(Factory.MyButton(text="Hello",amount=12))
class TestApp(App):
def build(self):
return Test()
if __name__ == '__main__':
TestApp().run()
@AlbericC
Copy link
Author

AlbericC commented Mar 9, 2015

useful stuff is on lines 15,16,and 29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment