The thing to keep in mind with scrollview is that the items to be scrolled must be sized.
Here is a short example:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
kv = """
BoxLayout:
ScrollView:
do_scroll_x: True
do_scroll_y: True
scroll_type:['bars', 'content']
bar_width: 20
ButtonGridLayout:
rows:20
cols:10
id: sv_grid
size_hint: None, None
size: self.minimum_width, self.minimum_height
"""
class ButtonGridLayout(GridLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
for i in range(200):
self.add_widget(Button(text=str(i), size_hint=(None,None), size=(200,48)))
class ScrollGridApp(App):
def build(self):
return Builder.load_string(kv)
ScrollGridApp().run()
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/5da249fb-378c-4660-8cd9-7c9b4e0430c2o%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.
The kv code is instancing the class, but the __init__ runs before the ids is setup or the attributes like rows and cols are set. You can use the on_kv_post event to run code after the kv code for the widget has been processed. In the example below, I moved the code from the __init__ to on_kv_post and used the number of cols and rows to create the appropriate number of buttons.
From the docs:
on_kv_post: (base_widget, )
Fired after all the kv rules associated with the widget and all other widgets that are in any of those rules have had all their kv rules applied. base_widget is the base-most widget whose instantiation triggered the kv rules (i.e. the widget instantiated from Python, e.g. MyWidget()).
https://kivy.org/doc/stable/api-kivy.uix.widget.html?highlight=widget#kivy.uix.widget.Widget
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
kv =
"""
BoxLayout:
ScrollView:
do_scroll_x: True
do_scroll_y: True
scroll_type:['bars', 'content']
bar_width: 10
ButtonGridLayout:
rows:20
cols:10
id: sv_grid
size_hint: None, None
size: self.minimum_width, self.minimum_height
"""
class ButtonGridLayout(GridLayout):
def on_kv_post(self, base_widget):
for i in range(self.rows * self.cols):
self.add_widget(Button(text=str(i), size_hint=(None,None), size=(200,48)))
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/83adbffd-e600-4f9f-8331-74d1328bdc5eo%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/83adbffd-e600-4f9f-8331-74d1328bdc5eo%40googlegroups.com.