Search code examples
pythonuser-interfacekivyscrollviewscrollbar

Scrollview is not working in python kivy app


I will need so much buttons and rows in my app I need scrollbar and scroll view in my other program scrolling is working but in this it is not working

from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.gridlayout import GridLayout
from kivy.uix.scrollview import ScrollView


class Program(App):
    def build(self):

        self.main_layout = BoxLayout(orientation = "vertical")

        self.firstrow = BoxLayout( size_hint_y=None, height=44)
        self.secondrow = BoxLayout( size_hint_y=None, height=44)
        #Actually there are so many rows thats why I need scrollview but I show you brief
        self.grid_izgara=GridLayout( cols=5, spacing=10, padding=10, size_hint_y=None )

        self.scroll_view = ScrollView(size_hint=(None, None), size=(700, 900))
        self.grid_izgara.bind(minimum_height=self.grid_izgara.setter("height"))
        self.eqn = Label(text= "Equation")
        self.equation = TextInput( size_hint_y=None, height=44)

        self.buton = Button(text="Drop Down Menu", size_hint_y=None, height=44)

        self.lowerBound = Label(text="Lower Bound", size_hint_y=None, height=44)
        self.lowerB = TextInput()
        self.upperBound = Label(text="Upper Bound", size_hint_y=None, height=44)
        self.upperB = TextInput()

        self.maxIteration = Label(text="Max Iteration", size_hint_y=None, height=44)
        self.maxI = TextInput()
        self.tolerance = Label(text="Toleration")
        self.toler = TextInput()

        self.solveButon = Button(text="Solve It")

        self.grid_izgara.add_widget(Button(text="bir", size_hint_y=None, height=44))
        self.grid_izgara.add_widget(Button(text="iki", size_hint_y=None, height=44))
        self.grid_izgara.add_widget(Button(text="uc", size_hint_y=None, height=44))
        self.grid_izgara.add_widget(Button(text="dort", size_hint_y=None, height=44))
        self.grid_izgara.add_widget(Button(text="bes", size_hint_y=None, height=44))

        self.grid_izgara.add_widget(Button(text="birsıfırw", size_hint_y=None, height=44))
        self.grid_izgara.add_widget(Button(text="ikisıfıwr", size_hint_y=None, height=44))
        self.grid_izgara.add_widget(Button(text="ucsıfıwr", size_hint_y=None, height=44))
        self.grid_izgara.add_widget(Button(text="dortsıfıwr", size_hint_y=None, height=44))
        self.grid_izgara.add_widget(Button(text="bessıfırw", size_hint_y=None, height=44))
        # Actually there are so many buttons thats why I need scrollview but I show you brief

        self.firstrow.add_widget(self.eqn)
        self.firstrow.add_widget(self.equation)

        self.secondrow.add_widget(self.solveButon)

        self.main_layout.add_widget(self.firstrow)
        self.main_layout.add_widget(self.buton)
        self.main_layout.add_widget(self.secondrow)

        self.main_layout.add_widget(self.grid_izgara)#Besinci Satırı ekledik
        self.scroll_view.add_widget(self.main_layout)
        return self.scroll_view



Program().run()

I prefer solving this problem with only python code without builder and .kv file. I can not handle them easily because of my limited knowledge.


Solution

  • You need to use minimum_height for the main_layout, just as you did for the grid_izgara. Like this:

        self.main_layout = BoxLayout(orientation = "vertical", size_hint_y=None)
        self.main_layout.bind(minimum_height=self.main_layout.setter('height'))