Kivy event on carousel when changing slides
I have no idea to find a solution to my problem.
I have a Carousel widget app. In this carousel I have 4 slides. welcomeSlide -> DVDSlide -> DVDPretSlide -> CategorySlide I am creating a class for each slide.
I am using ListAdpter to display data retrieved from Sqlite3 database.
My problem is with updating the list, when I change the DVD (add name for pret) in DVDSlide, when I go to DVDPret, the DVD does not appear because the List is not updated.
Similar to the documentation for the carousel, I don't see the event when the slides change. It is best if an event exists to get the current slide index.
Do you have an idea?
Thank,
source to share
You can observe the property index
:
from kivy.uix.carousel import Carousel
from kivy.uix.boxlayout import BoxLayout
from kivy.app import App
from kivy.lang import Builder
Builder.load_string('''
<Page>:
Label:
text: str(id(root))
<Carousel>
on_index: print("slide #{}".format(args[1]))
''')
class Page(BoxLayout):
pass
class TestApp(App):
def build(self):
root = Carousel()
for x in range(10):
root.add_widget(Page())
return root
if __name__ == '__main__':
TestApp().run()
Or you can observe the property current_slide
:
from kivy.uix.carousel import Carousel
from kivy.uix.boxlayout import BoxLayout
from kivy.app import App
from kivy.lang import Builder
Builder.load_string('''
<Page>:
label_id: label_id
Label:
id: label_id
text: str(id(root))
<Carousel>
on_current_slide: print(args[1].label_id.text)
''')
class Page(BoxLayout):
pass
class TestApp(App):
def build(self):
root = Carousel()
for x in range(10):
root.add_widget(Page())
return root
if __name__ == '__main__':
TestApp().run()
source to share