Skip to content
Advertisement

Kivy ScrollView code error with scrollbars (or bug?)

I’m playing around with a Kivy Scrollview, adding scrollbars, etc, and getting a strange crash. I don’t specifically think it’s a bug, it’s probably some configuration element on Scrollviews that I’m missing, but who knows?

Given this code:

"""
Source: https://stackoverflow.com/questions/35626320/kivy-image-scrolling
"""
from kivy.app import App
from kivy.uix.image import Image
from kivy.uix.scrollview import ScrollView
from kivy.core.window import Window

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

        some_img = Image(source='/home/data/map/Map_07C.jpg', size_hint=(None, None),
                         keep_ratio=True, size=(Window.width * 2, Window.height * 2))
        sv = ScrollView(size=Window.size, bar_width=50,
                        scroll_type=['bars', 'content'], effect_cls='ScrollEffect')
        sv.add_widget(some_img)

        return sv

if __name__ == "__main__":
    TutorialApp().run()

if I click or touch the Scrollbars in any way, I get this error:

   File "kivy_env/lib/python3.8/site-packages/kivy/uix/scrollview.py", line 908, in on_scroll_move
     self.effect_x.update(touch.x)
   File "kivy_env/lib/python3.8/site-packages/kivy/effects/scroll.py", line 116, in update
     self.displacement += abs(val - self.history[-1][1])
 IndexError: list index out of range 

However – if I first click the bitmap being scrolled, I can use the scrollbars with no problem.

So what’s up? Is there some Scrollview configuration I’m missing? (It took me a while to even find the scroll_type option to enable the bars, at first I could only mouse-drag the bitmap). Or is it a bug – given that it’s referencing history[-1], maybe that doesn’t exist yet?

Advertisement

Answer

Yep, it’s a bug. Just searched the Kivy repo on Github, found:

Effects Scroll Exception

The link does have a “workaround” patch, that you can manually apply to the installed library. Just tested the patch, it fixes my problem. Basically puts a try/except/return block around the line with history[-1]

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement