Last active
August 29, 2015 14:16
-
-
Save AlbericC/8262cb6b7e9516d6c03a to your computer and use it in GitHub Desktop.
Pass extra information to a kv-defined widget
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
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
useful stuff is on lines 15,16,and 29