Beginner: Adding x number of widgets to layout
Question: Really easy I'm sure but I'm learning Python & kivy (as a hobbyist not
professional).

I have made my first 'complex' kivy layout, and am now attempting to add
python code to it, and _I am fundamentally mis-understanding some things_. I
am keeping it all organised in seperate files where possible.

**1\. Within a GridLayout I have a ScrollView. All I want is to be able to add
'x' number of buttons to the ScrollView in it's python class.**

all relavent files ('...' indicating I have trimmed to only the relevant
parts)

**seatingmanager.py:**

    
    
    ...
    Builder.load_file('timescroll.kv')
    ...
    class SeatingManager(AnchorLayout):
        pass
    
    class SeatingManagerApp(App):
        def build(self):
            return SeatingManager()
    

**seatingmanager.kv:**

    
    
    <SeatingManager> 
        ...
        AnchorLayout:
            ...
            GridLayout:
                ...
                TimeScroll:
                    size_hint: None None
                    height: 50
                    width: 500
    

**2\. This is creating an instance of the TimeScroll class? This is where to
add specific attributes to this instance?**

timescroll.kv:

    
    
    #:import timescroll timescroll
    
    <TimeScroll>
    

**3\. This is where I can add attributes to all TimeScroll instances? If I am
not adding any is this file necessary (other than importing timescroll.py)?**

**timescroll.py:**(where I presume my problems lay)

    
    
    from kivy.uix.togglebutton import ToggleButton
    from kivy.uix.scrollview import ScrollView
    from kivy.uix.boxlayout import BoxLayout
    
    class TimeScroll(ScrollView):
        def build(self):
            layout = BoxLayout(orientation='vertical', size_hint_x=None,width=1500)
            for i in range(10):
                btn = ToggleButton(text=str(i), group='timeHeaders')
                layout.add_widget(btn)
            self.add_widget(layout)
            return layout
    

**4\. Is the build method automatically called when an instance of this class
is created? If not, why is it called automatically in the first file?**

**5\. This code doesn't work, simply leaves the ScrollView blank, so I presume
I am adding the BoxLayout to the ScrollView incorrectly or the build method
isn't automatically called.**


Answer: >   4. Is the build method automatically called when an instance of this class
> is created? If not, why is it called automatically in the first file?
>

The build method is never called for widgets, unless you do so yourself. You
should use the `__init__` method, as per normal python convention (and don't
forget to call `super`).

The App class has a build method that is called to start the user's own code,
but the App is not a widget, and this is the only place kivy will
automatically run a build method.

