'In a ScrollView, can I run a def if I reach the end of the list in a ScrollView or MDList?
How can I receive the event if I reach the bottom or end of the list
In a ScrollView, can I run a def if I reach the end of the list in a ScrollView or MDList?
App.py
from kivy.lang import Builder
from kivymd.app import MDApp
import kivymd_extensions.akivymd
from kivy.uix.screenmanager import ScreenManager, Screen
img = ["https://ar.anime-slayer.com/wp-content/uploads/2022/04/Ashampoo_Snap_2022.04.11_20h41m49s_005_-215x300.webp", "03.jpg", "13.jpg", "15.jpg", "24.jpg", "28.jpg", "29.jpg", "33.jpg", "34.jpg"]
KV = """
<MyTile@SmartTile>
size_hint_y: None
height: "240dp"
ScrollView:
id: scroll
MDGridLayout:
id: grid
cols: 3
adaptive_height: True
padding: dp(4), dp(4)
spacing: dp(4)
MyTile:
source:"https://ar.anime-slayer.com/wp-content/uploads/2022/04/Ashampoo_Snap_2022.04.11_20h41m49s_005_-215x300.webp"
MyTile:
source:"15.jpg"
MyTile:
source:"24.jpg"
MyTile:
source:"13.jpg"
"""
class Test(MDApp):
def build(self):
#self.ids.grid.add_widget(SmartTile(source = img[0]))
return Builder.load_string(KV)
Test().run()
Solution 1:[1]
You can bind a callback method to the prop. scroll_y or override default method on_scroll_y with the necessary logic which, if not implemented properly, can be unstable.
However adding a Button at the end of your widget tree inside ScrollView and triggering an event once you reach the end can be simple and suitable for your needs.
Here is the implementation of that design.
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.factory import Factory
import kivymd_extensions.akivymd
from kivy.uix.screenmanager import ScreenManager, Screen
img = ["https://ar.anime-slayer.com/wp-content/uploads/2022/04/Ashampoo_Snap_2022.04.11_20h41m49s_005_-215x300.webp", "03.jpg", "13.jpg", "15.jpg", "24.jpg", "28.jpg", "29.jpg", "33.jpg", "34.jpg"]
KV = """
<MyTile@SmartTile>
size_hint_y: None
height: "240dp"
ScrollView:
id: scroll
MDBoxLayout:
orientation: "vertical"
adaptive_height: True
MDGridLayout:
id: grid
cols: 3
adaptive_height: True
padding: dp(4), dp(4)
spacing: dp(4)
MyTile:
source:"https://ar.anime-slayer.com/wp-content/uploads/2022/04/Ashampoo_Snap_2022.04.11_20h41m49s_005_-215x300.webp"
MyTile:
source:"15.jpg"
MyTile:
source:"24.jpg"
MyTile:
source:"13.jpg"
Button:
size_hint_y: None
height: dp(25)
text: "Load more photos"
on_release: app.add_more_images()
"""
class Test(MDApp):
def build(self):
return Builder.load_string(KV)
def add_more_images(self, *args):
grid = self.root.ids.grid
# Add images from the list.
for img_src in img:
tile = Factory.MyTile(source = img_src)
grid.add_widget(tile)
Test().run()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ApuCoder |
