0
votes

I'm having issues with this kivy app, how do I add buttons to this? I tried using string builder to add labels, buttons, and other widgets, but to no luck. My code is oriented this way because I couldn't get Recycleview to work properly, so excuse the mess.

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.recycleview import RecycleView
import sqlite3
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.widget import Widget


Builder.load_string('''
<RV>:
    viewclass: 'Label'
    RecycleBoxLayout:
    default_size: None, dp(36)
    default_size_hint: 1, None
    size_hint_y: None
    height: self.minimum_height
    orientation: 'vertical'
''')


class RV(RecycleView):
    def __init__(self, **kwargs):
        super(RV, self).__init__(**kwargs)
        try:
            conn = sqlite3.connect('UserInfo.db')
            cursor = conn.cursor()
            sqlite_select_query = """SELECT * from Login"""
            cursor.execute(sqlite_select_query)
            records = cursor.fetchall()

            self.data = [{'text': str(row[0]), 'color': (0, 0, 0, 1)}
                     for row in records]
            cursor.close()

        except sqlite3.Error as error:
            print("Failed to read data from sqlite table")


class TestApp(App):
    def build(self):
        return RV()


def runApp():
    TestApp().run()
# if __name__ == '__main__':
#   TestApp().run()
1

1 Answers

0
votes

First you have to keep a reference to your RV instance.
Something like self.rv = RV() and then return self.rv instead of return RV()

Then, you have to add a new dict (with a text and a color key) to your self.rv.data list, for every new item you want.

After that, you might need to call a self.rv.refresh_from_data().