StackLayout + ScrollView trouble

368 views
Skip to first unread message

Carlos Vieira

unread,
Jun 20, 2018, 4:17:00 PM6/20/18
to kivy-...@googlegroups.com
I'm at a loss, I can't get the StackLayout in the code below to stack its children properly. You can see in the image below there is no scroll bar in sight and the stack doesn't even start from the bottom.

It seems to stack fine if I remove "stack.size_hint_y = None". But as I understand it, that is necessary if I want scrolling to work (indeed, removing it makes it so the stacked widgets simply "overflow" to the right). Can anyone offer any insight? Thanks in advance.

Using python 3.6.5, Kivy v1.11.0.dev0

import kivy
kivy.require('1.11.0')

from kivy.app import App
from kivy.uix.stacklayout import StackLayout
from kivy.uix.scrollview import ScrollView
from kivy.uix.textinput import TextInput

class Arbrawf(App):

def build(self):
stack = StackLayout(orientation='bt-lr', padding=10, spacing=5)

# scrolling
stack.size_hint_y = None
stack.bind(minimum_height=stack.setter('height'))

for i in range(25):
stack.add_widget(TextInput(text=str(i), size_hint_y=None, height=35))

scroll = ScrollView(do_scroll_x=False)
scroll.add_widget(stack)
return scroll


if __name__ == '__main__':
Arbrawf().run()



ZenCODE

unread,
Jun 22, 2018, 9:01:08 AM6/22/18
to Kivy users support
The scrollbar does not appear until it's needed. And here it is not. It's also hidden by default as it's not required on touch devices.  Look for the word scroll and read up here:


Good luck

Daniel kolim

unread,
Jun 22, 2018, 5:29:56 PM6/22/18
to Kivy users support

ScrollView + StackLayout - orientation='bt-lr'


To create a scrollable TextInput widgets stacking from bottom to top, and then left to right, do the following:

  1. Set StackLayout size_hint_x to None because it is growing from left to right along x-axis
  2. Bind StackLayout's width to minimum width
  3. For each widget added dynamically,  set size_hint to (None, None)
  4. Set ScrollView's size_hint to (None, None) and size to window's size (Window.width, Window.height)


ScrollView + StackLayout - orientation='rl-tb'


Example

import kivy
kivy.require('1.11.0')

from kivy.app import App
from kivy.uix.stacklayout import StackLayout
from kivy.uix.scrollview import ScrollView
from kivy.uix.textinput import TextInput
from kivy.core.window import Window


class Demo(App):
title = "Kivy Scrollable StackLayout Orientation='bt-lr' Demo"

def build(self):
stack = StackLayout(orientation='bt-lr', padding=10, spacing=5)

# scrolling
        stack.size_hint_x = None
stack.bind(minimum_width=stack.setter('width'))

for i in range(200):
stack.add_widget(TextInput(text=str(i), write_tab=False, size_hint=(None, None), height=35))

scroll = ScrollView(size_hint=(None, None), size=(Window.width, Window.height),
bar_width=10, bar_color=[0, 1, 0, 1], bar_inactive_color=[1, 0, 0, 1],
effect_cls="ScrollEffect", scroll_type=['bars'])


scroll.add_widget(stack)
return scroll


if __name__ == '__main__':
    Demo().run()


Output

Carlos Vieira

unread,
Jun 22, 2018, 7:49:26 PM6/22/18
to Kivy users support
Daniel, thank you for the detailed answer! But what I intended, and should have made clear, was to have a sort of vertical Box Layout, but that stacks widgets from the bottom, instead of from the top. As you can see in the image below, that is perfectly possible, but I still haven't been able to make it so it continues to stack widgets up when inside a working Scroll View. If you or anyone else can shed some light on this on suggest some other way to go about it, I would be much obliged.

Thanks again

P.S. The image is reproducible from my original code by removing the "stack.size_hint_y = None" line and decreasing widgets being added.

Reply all
Reply to author
Forward
0 new messages