How can I control my Kivy scroll profile by dragging the sliders?

I'm new to Kivy and while I like the touch interface, I want my code to work well on non-touch computers.

Right now I have a scrollview with a gridlayout in it that is larger than the viewable area. I can very easily move my gaze by clicking on my screen or clicking and dragging to the background. I want to add a normal click and drag function to my scrollbar (like the scrollbar on the right side of your browser window).

I don't need the little up and down arrows, but I would like to be able to drag the scroll bar and move through the scroll.

I'm new to both SO and Kivy / Python, so I apologize if this is a bad question or poorly formulated.

+3


source to share


1 answer


Yes, you can do this: the ScrollView has a scroll_type property, so by setting it you can achieve what you want.

http://kivy.org/docs/api-kivy.uix.scrollview.html?highlight=scroll_type#kivy.uix.scrollview.ScrollView.scroll_type

you can change the bar_width property if you set scroll_type = ['bars'] because it defaults to 2 and it is too small to grab with the mouse



here's an example based on one in the docs:

layout = GridLayout(cols=1, spacing=10, size_hint_y=None)
# Make sure the height is such that there is something to scroll.
layout.bind(minimum_height=layout.setter('height'))
for i in range(30):
    btn = Button(text=str(i), size_hint_y=None, height=40)
    layout.add_widget(btn) 
root = ScrollView(size_hint=(None, None), size=(400, 400),
                scroll_type=['bars'], bar_width='10dp') #you can use both ['bars','content']
root.add_widget(layout)

      

you can browse the documents to see what else you can change based on your own needs.

+3


source







All Articles