прокрутите экран вниз для более длинного текста, как истории в киви - PullRequest
0 голосов
/ 20 апреля 2020

У меня есть экран в kivy, который я хочу прокрутить, так как текст в виджете метки не показывает весь текст, так же, как в kindle, мы можем прокручивать истории вниз. Кроме того, мой MainScreen унаследован от класса Screen. И по мере увеличения текста он не показывает последние 5 или 6 строк истории

вот мой код .kv этого класса

```
<MainScreen>:
    BoxLayout:
        canvas:
            Color:
                rgb: 0, 0, 0, 0
            Rectangle:
                size: self.size

        Label:
            id: story
            font_size: '20sp'
            height: self.texture_size[1]
            size: self.texture_size
            text_size: self.width, self.height
            halign: "auto"
            valign: "center"
            pos_hint: {"center_x": 0.7, "center_y": 0.49}

            text: 

"""A boy and a girl were playing together. The boy had a collection of marbles. The girl has some 
sweets with her. The boy told the girl that he would give her all his marbles in exchange for the 
sweets with her. The girl agreed.

The boy kept the most beautiful and the biggest marbles with him and gave her the remaining marbles. 
The girl gave him all her sweets as she promised. That night the girl slept peacefully. But the boy 
could not sleep as he kept wondering if the girl has hidden some sweets from him the way he had 
hidden the best marbles from her.

Moral of the Story :

If you do not give 100 percent in a relationship, you will always kept doubting if the other person 
has given her / his hundred percent. This is applicable for any relationship like love, employee – 
employer, friendship, family, countries, etc…
"""
            ```

вот класс MainScreen в файле .py

    class MainScreen(Screen):
        pass

Ответы [ 2 ]

0 голосов
/ 21 апреля 2020

Вот еще один ответ, но он содержит Label в ScrollView:

<MainScreen>:
    BoxLayout:
        pos_hint: {"center_x": 0.7, "center_y": 0.49}
        size_hint_y: None
        height: 150  # make smaller than Label to force scrolling
        canvas:
            Color:
                rgb: 0, 0, 0, 0
            Rectangle:
                size: self.size

        ScrollView:
            do_scroll_x: False
            Label:
                id: story
                font_size: '20sp'
                size_hint_y: None
                height: self.texture_size[1]
                text_size: root.width, None
                halign: "auto"
                valign: "center"

                text:

                    """A boy and a girl were playing together. The boy had a collection of marbles. The girl has some
                    sweets with her. The boy told the girl that he would give her all his marbles in exchange for the
                    sweets with her. The girl agreed.

                    The boy kept the most beautiful and the biggest marbles with him and gave her the remaining marbles.
                    The girl gave him all her sweets as she promised. That night the girl slept peacefully. But the boy
                    could not sleep as he kept wondering if the girl has hidden some sweets from him the way he had
                    hidden the best marbles from her.

                    Moral of the Story :

                    If you do not give 100 percent in a relationship, you will always kept doubting if the other person
                    has given her / his hundred percent. This is applicable for any relationship like love, employee –
                    employer, friendship, family, countries, etc…
                    """

Прочитайте эту важную часть документации ScrollView.

0 голосов
/ 21 апреля 2020

Чтобы сделать что-нибудь scroll, вам нужно использовать виджет ScrollView.

Вот как это можно реализовать в коде, который вы разместили

ScrollView:
    size_hint_y:None
    GridLayout:
        cols:1
        size_hint_y:None
        height:self.minimum_height
        canvas:
            Color:
                rgb: 0, 0, 0, 0
            Rectangle:
                size: self.size

        Label:
            id: story
            font_size: '20sp'
            height: self.texture_size[1]
            size: self.texture_size
            text_size: self.width, self.height
            halign: "auto"
            valign: "center"
            pos_hint: {"center_x": 0.7, "center_y": 0.49}

            text: 

        """A boy and a girl were playing together. The boy had a collection of marbles. The girl has some 
        sweets with her. The boy told the girl that he would give her all his marbles in exchange for the 
        sweets with her. The girl agreed.

        The boy kept the most beautiful and the biggest marbles with him and gave her the remaining marbles. 
        The girl gave him all her sweets as she promised. That night the girl slept peacefully. But the boy 
        could not sleep as he kept wondering if the girl has hidden some sweets from him the way he had 
        hidden the best marbles from her.

        Moral of the Story :

        If you do not give 100 percent in a relationship, you will always kept doubting if the other person 
        has given her / his hundred percent. This is applicable for any relationship like love, employee – 
        employer, friendship, family, countries, etc…
        """
            ```
...