Skip to content

Instantly share code, notes, and snippets.

@amalgamatedclyde
Created November 17, 2013 20:04
Show Gist options
  • Save amalgamatedclyde/7517620 to your computer and use it in GitHub Desktop.
Save amalgamatedclyde/7517620 to your computer and use it in GitHub Desktop.
instantiating dynamic class
if i use this loop outside of def build(self): i get this: kivy.factory.FactoryException: Unknown class <TravelerBtn>
if i change the widget in the for loop to 'Button,' i get 24 buttons in the stacklayout with the propertext.
if i use the loop within 'def build (self):', i can't set the text value of the <TravelerBtn> instances.
def build (self):
for i in range(25):
i = Factory.TravelerBtn(text =str(i))
rootwidget.add_widget(i)
return rootwidget
here is the kv rule:
<TravelerBtn@BoxLayout>:
size_hint: (None, None)
size: (200, 200)
text: 'None'
canvas.before:
Color:
rgba: (1, 0, 0, 1)
Rectangle:
pos: self.pos
size: self.size
Button:
size_hint: (None, None)
size: (180, 180)
text: root.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment