scrollview example without kv file

Showing 1-4 of 4 messages
scrollview example without kv file Rodrigo Liberal 7/11/12 4:02 PM
I was trying to implement the scrollview example without the kv file but I am finding it difficult.
Do you have a version like that?
Re: scrollview example without kv file qua-non 7/26/12 6:33 AM

from kivy.app import App
from kivy.uix.scrollview import ScrollView
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label

class SMApp(App):

    def build(self):
        layout = GridLayout(cols=1, spacing=10, size_hint_y=None)
        #Make sure the height is such that there is something to scroll.
        layout.bind(minimum_height=layout.setter('height'))
        for i in range(30):
            btn = Label(text=str(i), size_hint_y=None, height=40)
            layout.add_widget(btn)
        root = ScrollView(size_hint=(None, None), size=(400, 400),
            pos_hint={'center_x':.5, 'center_y':.5})
        root.add_widget(layout)
        return root

if __name__ == '__main__':
    SMApp().run()
This is actually taken from the documentation, http://kivy.org/docs/api-kivy.uix.scrollview.html#managing-the-content-size
I'm curious what part were you having difficulty with?
Re: scrollview example without kv file Gerald Ikenna 2/5/17 4:43 AM
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.scrollview import ScrollView
from kivy.core.window import Window
from kivy.app import runTouchApp

layout = GridLayout(cols=1, spacing=10, size_hint_y=None)
# Make sure the height is such that there is something to scroll.
layout.bind(minimum_height=layout.setter('height'))
for i in range(100):
    btn = Button(text=str(i), size_hint_y=None, height=40)
    layout.add_widget(btn)
root = ScrollView(size_hint=(1, None), size=(Window.width, Window.height))
root.add_widget(layout)

runTouchApp(root)

Re: scrollview example without kv file sebastian lopez 2/5/17 6:30 AM
Hi

I have used this code adpated from kivymd

from kivy.uix.scrollview import ScrollView
from kivy.uix.gridlayout import GridLayout

class Contenedor(GridLayout):
    _bind = True
    def __init__(self, *args, **kwargs):
        kwargs['size_hint_y'] = None
        kwargs['cols'] = 1
        super(Contenedor, self).__init__(*args, **kwargs)
    def add_widget(self, widget, index=0):
        if self._bind:
            self.bind(minimum_height=self.setter('height'))
            self._bind = False
        super(Contenedor, self).add_widget(widget, index)
        self.height += widget.height
    def del_widget(self, widget):
        super(Contenedor, self).del_widget(widget)
        self.height -= wigdet.height        
    
class Container(ScrollView):
    def __init__(self, *args, **kwargs):
        kwargs['do_scroll_x'] = False
        super(Container, self).__init__(*args, **kwargs)
        self._grid_widget = Contenedor()
        super(Container, self).add_widget(self._grid_widget)
    @property
    def childs(self):
        return self._grid_widget.children
    def add_widget(self, widget, index=0):
        self._grid_widget.add_widget(widget, index=0)
    def del_widget(self, widget):
        self._grid_widget.del_widget(widget)

You should use the Container class, also you can use it under the kv languaje