I was able to get my layout working with static kivy language but I need to be able to add items to my list via python. I've tried several things but can't seem to get anything working correctly. Here's what I have working statically.
main.py
#!/usr/bin/python
import os
import kivy
kivy.require('1.8.0')
from kivy.app import App
from kivy.core.window import Window
from kivy.logger import Logger
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
class CustomButton(Button):
pass
def click(button):
Logger.info(button.title + ": wid=" + button.wid)
class SelectFruit(App, BoxLayout):
icon = 'ico/fruit.png'
title = 'Awesome Fruit Picker'
def build(self):
Window.size = 400, (4 * 78)
return SelectFruit()
if __name__ in ('__main__'):
SelectFruit().run()
selectfruit.kv
#:kivy 1.8.0
<CustomButton@Button>:
wid: ""
image: ''
title: ''
label: ''
on_press: self.click()
BoxLayout:
orientation: "horizontal"
size: self.parent.size # match the button's size
pos: self.parent.pos # match the button's position
padding: 5
spacing: 10
Image:
size_hint: None, 1
source: root.image
size: 64, 64
valign: "middle"
Label:
size_hint: None, 1
text: root.label
valign: "middle"
size: 400, 64
text_size: self.size
<SelectFruit>
orientation: "vertical"
padding: 2
CustomButton:
wid: "0"
image: "ico/apple.png"
title: "apple"
label: "Apple: Super Sweet\nPicked On: 12/26/2014, 2:01 PM"
CustomButton:
wid: "1"
image: "ico/banana.png"
title: "banana"
label: "Banana: Want a bunch?\nPicked On: 2/18/2014, 2:01 PM"
CustomButton:
wid: "2"
image: "ico/strawberry.png"
title: "strawberry"
label: "Strawberry: Yummy Yummy\nPicked On: 5/6/2014, 2:01 PM"
CustomButton:
wid: "3"
image: "ico/orange.png"
title: "orange"
label: "Orange: Florida's Best\nPicked On: 4/21/2014, 2:01 PM"
I just need to be able to add each CustomButton programmatically to my layout rather than via the kivy language file. Any help is greatly appreciated.