Last active
February 20, 2021 17:40
-
-
Save dustinfarris/8760770 to your computer and use it in GitHub Desktop.
Dynamic lists in Kivy
This file contains hidden or 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
#:import la kivy.adapters.listadapter | |
#:import listview kivy.uix.listview | |
<MyList>: | |
adapter: la.ListAdapter( | |
data=[], | |
args_converter=self.list_item_args_converter, | |
cls=listview.ListItemButton) | |
<MyScreen>: | |
my_list: my_list | |
MyList: | |
id: my_list |
This file contains hidden or 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
class MyObject: | |
def __init__(self, text=''): | |
self.text = text | |
class MyList(ListView): | |
def list_item_args_converter(self, row_index, obj): | |
return {'text': obj.text} | |
def update(self): | |
self.adapter.data = [ | |
MyObject('Fred'), | |
MyObject('Bob'), | |
] | |
class MyScreen(Screen): | |
my_list = ObjectProperty() | |
def on_pre_enter(self): | |
self.my_list.update() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment