You could add the image as a child of the Button widgets. Or subclass the Button class to add an 'icon' ObjectProperty and adapt the text placement for the icon size if you want both.
I've already got a button with a custom up and pressed state images, but I'd like to be able to add an icon to it as well without having to make an whole new image for each button state each time (I'm stepping through a list of iterations to set up my buttons and I want to be able to change the icons on each of them at any time).
--
def BuildLayout(self): layout = GridLayout( rows=4, row_force_default = True, row_default_height = 100, col_force_default = True, col_default_width = 300 )
with open('config.txt', 'rb') as f: reader = csv.reader(f, delimiter="|") for row in reader:
class IconButton(Button): icon = StringProperty(row[2])
launchbutton = IconButton( text = row[0], background_normal = 'tile.png' ) launchbutton.bind( on_release = lambda widget, appname=row[1]: self.Launcher( appname ) ) layout.add_widget(launchbutton)
return layoutIconButton(Button, blah):
icon = blahworks I guess...but you dont have to declare the IconButton inside the
loop. you can just define it at module level if you want...otherwise
your technically redefining the class each time through the loop.
> --
>
>
>