SaikiHanee SaikiHanee - 3 months ago 23
Python Question

Add a ScrollView to kivy Popup

I am trying to add a ScrollView to a Popup which opens when button is clicked on the main interface. But the scrollview is not displaying the content properly. How can I fix this?

from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.popup import Popup
from kivy.uix.scrollview import ScrollView
from kivy.app import App
from kivy.core.window import Window

def btn_clicked(instance):
layout_popup = GridLayout(cols=1, spacing=10, size_hint_y=None)
layout_popup.bind(minimum_height=layout_popup.setter('height'))

for i in range(0, 15):
btn1 = Button(text=str(i), id=str(i))
layout_popup.add_widget(btn1)

root = ScrollView(size_hint=(1, None), size=(Window.width, Window.height))
root.add_widget(layout_popup)
popup = Popup(title='Numbers', content=root, size_hint=(1, 1))
popup.open()

class TutorialApp(App):
def build(self):
g = GridLayout(cols=1)
btn = Button(text='Click')
btn.bind(on_press=btn_clicked)
g.add_widget(btn)
return g


TutorialApp().run()

Answer

Pass size_hint_y=None to the button constructor and it should work.