Reputation: 57
So, I know there have been couple of similar questions but I haven't found a solution on any of those questions. When I click one button in my RecycleView screen in my kivy app different button flashes. I haven't changed anything about buttons so I don't see any mistake in my code but there might be something that I have not seen. Here is the code:
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
from kivy.uix.recycleview import RecycleView
from kivy.app import App
class Kupci_sve(RecycleView, Screen):
def __init__(self, **kwargs):
super(Kupci_sve, self).__init__(**kwargs)
self.data = [{"text": str(i)} for i in range(20)]
self.bar_width = 8
self.scroll_type = ['bars']
kv = Builder.load_string('''
<Kupci_sve>:
name: 'kupci_sve'
viewclass: 'Button'
RecycleBoxLayout:
default_size: (None, 100)
default_size_hint: (1, None)
size_hint_y: None
height: self.minimum_height
orientation: "vertical"
''')
class app(App):
def build(self):
return Kupci_sve()
if __name__ == '__main__':
app().run()
I import this screen to my main.py file and run it from there but I didn't paste that code because I think it has nothing to do with this problem. If you need any other info, just tell me. Thank you.
Upvotes: 3
Views: 97
Reputation: 39012
Without a minimal, complete, reproducible example, I suspect your problem may be in making your Kupci_sve
class extend both Screen
and RecycleView
. A better approach would be to just extend Screen
and simply include a RecycleView
in the kv
rule for <Kupci_sve>
.
Here is what I mean:
<Kupci_sve>:
name: 'kupci_sve'
RecycleView:
id: rv # added id
bar_width: 8
scroll_type: ['bars']
viewclass: 'Button'
RecycleBoxLayout:
default_size: (None, 100)
default_size_hint: (1, None)
size_hint_y: None
height: self.minimum_height
orientation: "vertical"
And the Kupci_sve
class becomes:
class Kupci_sve(Screen):
def __init__(self, **kwargs):
super(Kupci_sve, self).__init__(**kwargs)
self.ids.rv.data = [{"text": str(i), "on_release":partial(self.butt_release, i)} for i in range(20)]
def butt_release(self, index):
print('butt_release:', index)
Upvotes: 1