Nithishbn
Nithishbn

Reputation: 23

How can I create an automatic scrollable label in Kivy?

I am developing an application that has some buttons on the top with a scrollable Label on the bottom. I want to have the scrollable label automatically scrolling from right to left similar to what one may see on the News.

<marquee>N e w s</marquee>

I know how to make a scrollable label but I'm not sure how to move it automatically.

Upvotes: 2

Views: 1421

Answers (2)

Peter Badida
Peter Badida

Reputation: 12159

To make a scrollable label there's a small piece of code usable directly from kv lang. First set the size_hint_x to None, so that it can be scaled up to the width of texture_size.

from kivy.lang import Builder
from kivy.base import runTouchApp
from kivy.animation import Animation
from kivy.uix.scrollview import ScrollView
Builder.load_string('''
<Spacer@Widget>:
    size_hint_x: None
    width: 800

<ScrollLabel>:
    GridLayout:
        rows: 1
        size_hint_x: None
        width: self.minimum_width
        Spacer:
        Label:
            size_hint_x: None
            text: 'l or emi psum '*100
            width: self.texture_size[0]
        Spacer:
''')
class ScrollLabel(ScrollView): pass
scroll = ScrollLabel(scroll_y=-1)
marquee = Animation(scroll_x=1, duration=100.0)
marquee.start(scroll)
runTouchApp(scroll)

And to make it scroll just use Animation. You can also use Widget as a spacer, so that your text appeared visually like the html marquee tag i.e. scrolling into an empty space, and not scrolling already visible text.

Upvotes: 2

redAllocator
redAllocator

Reputation: 735

Just make the top-level layout a ScrollView this following like:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">  
</ScrollView>

If you want to scrollview in detail, connect to this site:

https://developer.android.com/reference/android/widget/ScrollView.html

Upvotes: 0

Related Questions